diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 25ffd5dd6e..76aa51aac6 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -314,6 +314,7 @@ endif() ##### base cocos_source_files( + cocos/base/Agent.h NO_WERROR cocos/base/Array.cpp cocos/base/Array.h NO_WERROR cocos/base/astc.cpp @@ -610,6 +611,8 @@ endif() ##### renderer cocos_source_files( + cocos/renderer/GFXDeviceCreator.h + cocos/renderer/gfx-base/GFXObject.h NO_WERROR cocos/renderer/gfx-base/GFXObject.cpp cocos/renderer/gfx-base/GFXBase.h @@ -650,36 +653,65 @@ cocos_source_files( cocos/renderer/gfx-base/GFXTexture.h NO_WERROR cocos/renderer/gfx-base/GFXTextureBarrier.cpp cocos/renderer/gfx-base/GFXTextureBarrier.h - cocos/renderer/gfx-agent/GFXAgent.h - cocos/renderer/gfx-agent/GFXBufferAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXBufferAgent.cpp - cocos/renderer/gfx-agent/GFXCommandBufferAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXCommandBufferAgent.cpp - cocos/renderer/gfx-agent/GFXDescriptorSetAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXDescriptorSetAgent.cpp - cocos/renderer/gfx-agent/GFXDescriptorSetLayoutAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXDescriptorSetLayoutAgent.cpp - cocos/renderer/gfx-agent/GFXDeviceAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXDeviceAgent.cpp - cocos/renderer/gfx-agent/GFXFramebufferAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXFramebufferAgent.cpp - cocos/renderer/gfx-agent/GFXInputAssemblerAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXInputAssemblerAgent.cpp - cocos/renderer/gfx-agent/GFXLinearAllocatorPool.h - cocos/renderer/gfx-agent/GFXPipelineLayoutAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXPipelineLayoutAgent.cpp - cocos/renderer/gfx-agent/GFXPipelineStateAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXPipelineStateAgent.cpp - cocos/renderer/gfx-agent/GFXQueueAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXQueueAgent.cpp - cocos/renderer/gfx-agent/GFXRenderPassAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXRenderPassAgent.cpp - cocos/renderer/gfx-agent/GFXSamplerAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXSamplerAgent.cpp - cocos/renderer/gfx-agent/GFXShaderAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXShaderAgent.cpp - cocos/renderer/gfx-agent/GFXTextureAgent.h - NO_WERROR cocos/renderer/gfx-agent/GFXTextureAgent.cpp + cocos/renderer/gfx-agent/BufferAgent.h + NO_WERROR cocos/renderer/gfx-agent/BufferAgent.cpp + cocos/renderer/gfx-agent/CommandBufferAgent.h + NO_WERROR cocos/renderer/gfx-agent/CommandBufferAgent.cpp + cocos/renderer/gfx-agent/DescriptorSetAgent.h + NO_WERROR cocos/renderer/gfx-agent/DescriptorSetAgent.cpp + cocos/renderer/gfx-agent/DescriptorSetLayoutAgent.h + NO_WERROR cocos/renderer/gfx-agent/DescriptorSetLayoutAgent.cpp + cocos/renderer/gfx-agent/DeviceAgent.h + NO_WERROR cocos/renderer/gfx-agent/DeviceAgent.cpp + cocos/renderer/gfx-agent/FramebufferAgent.h + NO_WERROR cocos/renderer/gfx-agent/FramebufferAgent.cpp + cocos/renderer/gfx-agent/InputAssemblerAgent.h + NO_WERROR cocos/renderer/gfx-agent/InputAssemblerAgent.cpp + cocos/renderer/gfx-agent/LinearAllocatorPool.h + cocos/renderer/gfx-agent/PipelineLayoutAgent.h + NO_WERROR cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp + cocos/renderer/gfx-agent/PipelineStateAgent.h + NO_WERROR cocos/renderer/gfx-agent/PipelineStateAgent.cpp + cocos/renderer/gfx-agent/QueueAgent.h + NO_WERROR cocos/renderer/gfx-agent/QueueAgent.cpp + cocos/renderer/gfx-agent/RenderPassAgent.h + NO_WERROR cocos/renderer/gfx-agent/RenderPassAgent.cpp + cocos/renderer/gfx-agent/SamplerAgent.h + NO_WERROR cocos/renderer/gfx-agent/SamplerAgent.cpp + cocos/renderer/gfx-agent/ShaderAgent.h + NO_WERROR cocos/renderer/gfx-agent/ShaderAgent.cpp + cocos/renderer/gfx-agent/TextureAgent.h + NO_WERROR cocos/renderer/gfx-agent/TextureAgent.cpp + cocos/renderer/gfx-empty/EmptyBuffer.h + NO_WERROR cocos/renderer/gfx-empty/EmptyBuffer.cpp + cocos/renderer/gfx-empty/EmptyCommandBuffer.h + NO_WERROR cocos/renderer/gfx-empty/EmptyCommandBuffer.cpp + cocos/renderer/gfx-empty/EmptyContext.h + NO_WERROR cocos/renderer/gfx-empty/EmptyContext.cpp + cocos/renderer/gfx-empty/EmptyDescriptorSet.h + NO_WERROR cocos/renderer/gfx-empty/EmptyDescriptorSet.cpp + cocos/renderer/gfx-empty/EmptyDescriptorSetLayout.h + NO_WERROR cocos/renderer/gfx-empty/EmptyDescriptorSetLayout.cpp + cocos/renderer/gfx-empty/EmptyDevice.h + NO_WERROR cocos/renderer/gfx-empty/EmptyDevice.cpp + cocos/renderer/gfx-empty/EmptyFramebuffer.h + NO_WERROR cocos/renderer/gfx-empty/EmptyFramebuffer.cpp + cocos/renderer/gfx-empty/EmptyInputAssembler.h + NO_WERROR cocos/renderer/gfx-empty/EmptyInputAssembler.cpp + cocos/renderer/gfx-empty/EmptyPipelineLayout.h + NO_WERROR cocos/renderer/gfx-empty/EmptyPipelineLayout.cpp + cocos/renderer/gfx-empty/EmptyPipelineState.h + NO_WERROR cocos/renderer/gfx-empty/EmptyPipelineState.cpp + cocos/renderer/gfx-empty/EmptyQueue.h + NO_WERROR cocos/renderer/gfx-empty/EmptyQueue.cpp + cocos/renderer/gfx-empty/EmptyRenderPass.h + NO_WERROR cocos/renderer/gfx-empty/EmptyRenderPass.cpp + cocos/renderer/gfx-empty/EmptySampler.h + NO_WERROR cocos/renderer/gfx-empty/EmptySampler.cpp + cocos/renderer/gfx-empty/EmptyShader.h + NO_WERROR cocos/renderer/gfx-empty/EmptyShader.cpp + cocos/renderer/gfx-empty/EmptyTexture.h + NO_WERROR cocos/renderer/gfx-empty/EmptyTexture.cpp NO_WERROR cocos/renderer/pipeline/BatchedBuffer.cpp cocos/renderer/pipeline/BatchedBuffer.h cocos/renderer/pipeline/Define.h @@ -965,6 +997,31 @@ if(CC_USE_VULKAN) ) endif() +cocos_source_files( + cocos/renderer/frame-graph/Blackboard.h + cocos/renderer/frame-graph/CallbackPass.h + cocos/renderer/frame-graph/DevicePass.cpp + cocos/renderer/frame-graph/DevicePass.h + cocos/renderer/frame-graph/DevicePassResourceTable.cpp + cocos/renderer/frame-graph/DevicePassResourceTable.h + cocos/renderer/frame-graph/FrameGraph.cpp + cocos/renderer/frame-graph/FrameGraph.h + cocos/renderer/frame-graph/Handle.h + cocos/renderer/frame-graph/PassInsertPointManager.cpp + cocos/renderer/frame-graph/PassInsertPointManager.h + cocos/renderer/frame-graph/PassNode.cpp + cocos/renderer/frame-graph/PassNode.h + cocos/renderer/frame-graph/PassNodeBuilder.cpp + cocos/renderer/frame-graph/PassNodeBuilder.h + cocos/renderer/frame-graph/RenderTargetAttachment.h + cocos/renderer/frame-graph/Resource.h + cocos/renderer/frame-graph/ResourceAllocator.h + cocos/renderer/frame-graph/ResourceEntry.h + cocos/renderer/frame-graph/ResourceNode.h + cocos/renderer/frame-graph/VirtualResource.cpp + cocos/renderer/frame-graph/VirtualResource.h +) + ##### script bindings ######## dop cocos_source_files( @@ -1312,8 +1369,6 @@ cocos_source_files( cocos/bindings/manual/jsb_conversions.h NO_WERROR cocos/bindings/manual/jsb_gfx_manual.cpp cocos/bindings/manual/jsb_gfx_manual.h - NO_WERROR cocos/bindings/manual/jsb_gfx_agent.cpp - cocos/bindings/manual/jsb_gfx_agent.h NO_WERROR cocos/bindings/manual/jsb_global.cpp cocos/bindings/manual/jsb_global.h NO_WERROR cocos/bindings/manual/jsb_global_init.cpp @@ -1364,34 +1419,6 @@ elseif(WIN32) ) endif() -if(CC_USE_GLES2) - cocos_source_files( - cocos/bindings/auto/jsb_gles2_auto.h - NO_WERROR cocos/bindings/auto/jsb_gles2_auto.cpp - ) -endif() - -if(CC_USE_GLES3) - cocos_source_files( - cocos/bindings/auto/jsb_gles3_auto.h - NO_WERROR cocos/bindings/auto/jsb_gles3_auto.cpp - ) -endif() - -if(CC_USE_METAL) - cocos_source_files( - cocos/bindings/auto/jsb_mtl_auto.h - NO_WERROR cocos/bindings/auto/jsb_mtl_auto.cpp - ) -endif() - -if(CC_USE_VULKAN) - cocos_source_files( - cocos/bindings/auto/jsb_vk_auto.h - NO_WERROR cocos/bindings/auto/jsb_vk_auto.cpp - ) -endif() - if(USE_SE_V8) cocos_source_files( cocos/bindings/jswrapper/v8/Base.h diff --git a/native/cocos/renderer/gfx-agent/GFXAgent.h b/native/cocos/base/Agent.h similarity index 91% rename from native/cocos/renderer/gfx-agent/GFXAgent.h rename to native/cocos/base/Agent.h index 78578b9823..6382837d93 100644 --- a/native/cocos/renderer/gfx-agent/GFXAgent.h +++ b/native/cocos/base/Agent.h @@ -26,18 +26,16 @@ #pragma once #include -#include "gfx-base/GFXDevice.h" namespace cc { -namespace gfx { template class CC_DLL Agent : public Actor { public: Agent() noexcept = delete; - Agent(Actor *const actor, Device *const device) noexcept - : Actor(device), _actor(actor) {} + Agent(Actor *const actor) noexcept + : Actor(), _actor(actor) {} ~Agent() override {} @@ -55,5 +53,4 @@ protected: Actor *_actor{nullptr}; }; -} // namespace gfx } // namespace cc diff --git a/native/cocos/base/threading/MessageQueue.cpp b/native/cocos/base/threading/MessageQueue.cpp index c58a7ed6aa..dce0ab17fc 100644 --- a/native/cocos/base/threading/MessageQueue.cpp +++ b/native/cocos/base/threading/MessageQueue.cpp @@ -88,15 +88,15 @@ void MessageQueue::MemoryAllocator::free(uint8_t *const chunk) noexcept { MessageQueue::MessageQueue() { uint8_t *const chunk = MemoryAllocator::getInstance().request(); - _writer._currentMemoryChunk = chunk; - _reader._currentMemoryChunk = chunk; + _writer.currentMemoryChunk = chunk; + _reader.currentMemoryChunk = chunk; // sentinel node will not be executed Message *const msg = allocate(1); pushMessages(); pullMessages(); - _reader._lastMessage = msg; - --_reader._newMessageCount; + _reader.lastMessage = msg; + --_reader.newMessageCount; } void MessageQueue::kick() noexcept { @@ -119,9 +119,10 @@ void MessageQueue::kickAndWait() noexcept { } void MessageQueue::runConsumerThread() noexcept { - if (_workerAttached) { - return; - } + if (_immediateMode || _workerAttached) return; + + _reader.terminateConsumerThread = false; + _reader.flushingFinished = false; std::thread consumerThread(&MessageQueue::consumerThreadLoop, this); consumerThread.detach(); @@ -129,9 +130,7 @@ void MessageQueue::runConsumerThread() noexcept { } void MessageQueue::terminateConsumerThread() noexcept { - if (!_workerAttached) { - return; - } + if (_immediateMode || !_workerAttached) return; EventSem event; EventSem *const pEvent = &event; @@ -146,7 +145,7 @@ void MessageQueue::terminateConsumerThread() noexcept { void MessageQueue::finishWriting(bool wait) noexcept { if (!_immediateMode) { - bool *const flushingFinished = &_reader._flushingFinished; + bool *const flushingFinished = &_reader.flushingFinished; ENQUEUE_MESSAGE_1(this, finishWriting, flushingFinished, flushingFinished, @@ -174,22 +173,22 @@ uint8_t *MessageQueue::allocateImpl(uint32_t &allocatedSize, uint32_t const requ uint32_t const alignedSize = align(requestSize, 16); assert(alignedSize + SWITCH_CHUNK_MEMORY_REQUIREMENT <= MEMORY_CHUNK_SIZE); // exceeds the block size - uint32_t const newOffset = _writer._offset + alignedSize; + uint32_t const newOffset = _writer.offset + alignedSize; if (newOffset + SWITCH_CHUNK_MEMORY_REQUIREMENT <= MEMORY_CHUNK_SIZE) { allocatedSize = alignedSize; - uint8_t *const allocatedMemory = _writer._currentMemoryChunk + _writer._offset; - _writer._offset = newOffset; + uint8_t *const allocatedMemory = _writer.currentMemoryChunk + _writer.offset; + _writer.offset = newOffset; return allocatedMemory; } else { uint8_t *const newChunk = MessageQueue::MemoryAllocator::getInstance().request(); - MemoryChunkSwitchMessage *const switchMessage = reinterpret_cast(_writer._currentMemoryChunk + _writer._offset); - new (switchMessage) MemoryChunkSwitchMessage(this, newChunk, _writer._currentMemoryChunk); + MemoryChunkSwitchMessage *const switchMessage = reinterpret_cast(_writer.currentMemoryChunk + _writer.offset); + new (switchMessage) MemoryChunkSwitchMessage(this, newChunk, _writer.currentMemoryChunk); switchMessage->_next = reinterpret_cast(newChunk); // point to start position - _writer._lastMessage = switchMessage; - ++_writer._pendingMessageCount; - _writer._currentMemoryChunk = newChunk; - _writer._offset = 0; + _writer.lastMessage = switchMessage; + ++_writer.pendingMessageCount; + _writer.currentMemoryChunk = newChunk; + _writer.offset = 0; DummyMessage *const head = allocate(1); new (head) DummyMessage; @@ -197,7 +196,7 @@ uint8_t *MessageQueue::allocateImpl(uint32_t &allocatedSize, uint32_t const requ if (_immediateMode) { pushMessages(); pullMessages(); - assert(_reader._newMessageCount == 2); + assert(_reader.newMessageCount == 2); executeMessages(); executeMessages(); } @@ -207,22 +206,22 @@ uint8_t *MessageQueue::allocateImpl(uint32_t &allocatedSize, uint32_t const requ } void MessageQueue::pushMessages() noexcept { - _writer._writtenMessageCount.fetch_add(_writer._pendingMessageCount, std::memory_order_acq_rel); - _writer._pendingMessageCount = 0; + _writer.writtenMessageCount.fetch_add(_writer.pendingMessageCount, std::memory_order_acq_rel); + _writer.pendingMessageCount = 0; } void MessageQueue::pullMessages() noexcept { - uint32_t const writtenMessageCountNew = _writer._writtenMessageCount.load(std::memory_order_acquire); - _reader._newMessageCount += writtenMessageCountNew - _reader._writtenMessageCountSnap; - _reader._writtenMessageCountSnap = writtenMessageCountNew; + uint32_t const writtenMessageCountNew = _writer.writtenMessageCount.load(std::memory_order_acquire); + _reader.newMessageCount += writtenMessageCountNew - _reader.writtenMessageCountSnap; + _reader.writtenMessageCountSnap = writtenMessageCountNew; } void MessageQueue::flushMessages() noexcept { - while (!_reader._flushingFinished) { + while (!_reader.flushingFinished) { executeMessages(); } - _reader._flushingFinished = false; + _reader.flushingFinished = false; } void MessageQueue::executeMessages() noexcept { @@ -246,15 +245,15 @@ Message *MessageQueue::readMessage() noexcept { } } - Message *const msg = _reader._lastMessage->getNext(); - _reader._lastMessage = msg; - --_reader._newMessageCount; + Message *const msg = _reader.lastMessage->getNext(); + _reader.lastMessage = msg; + --_reader.newMessageCount; assert(msg); return msg; } void MessageQueue::consumerThreadLoop() noexcept { - while (!_reader._terminateConsumerThread) { + while (!_reader.terminateConsumerThread) { flushMessages(); } @@ -276,7 +275,7 @@ MemoryChunkSwitchMessage::~MemoryChunkSwitchMessage() { } void MemoryChunkSwitchMessage::execute() noexcept { - _messageQueue->_reader._currentMemoryChunk = _newChunk; + _messageQueue->_reader.currentMemoryChunk = _newChunk; _messageQueue->pullMessages(); } @@ -290,8 +289,8 @@ TerminateConsumerThreadMessage::TerminateConsumerThreadMessage(EventSem *const p } void TerminateConsumerThreadMessage::execute() noexcept { - _reader->_terminateConsumerThread = true; - _reader->_flushingFinished = true; + _reader->terminateConsumerThread = true; + _reader->flushingFinished = true; _event->signal(); } diff --git a/native/cocos/base/threading/MessageQueue.h b/native/cocos/base/threading/MessageQueue.h index 85afb65a2f..5c4725b49f 100644 --- a/native/cocos/base/threading/MessageQueue.h +++ b/native/cocos/base/threading/MessageQueue.h @@ -66,21 +66,21 @@ private: }; struct alignas(64) WriterContext final { - uint8_t * _currentMemoryChunk{nullptr}; - Message * _lastMessage{nullptr}; - uint32_t _offset{0}; - uint32_t _pendingMessageCount{0}; - std::atomic _writtenMessageCount{0}; + uint8_t * currentMemoryChunk{nullptr}; + Message * lastMessage{nullptr}; + uint32_t offset{0}; + uint32_t pendingMessageCount{0}; + std::atomic writtenMessageCount{0}; }; struct alignas(64) ReaderContext final { - uint8_t *_currentMemoryChunk{nullptr}; - Message *_lastMessage{nullptr}; - uint32_t _offset{0}; - uint32_t _writtenMessageCountSnap{0}; - uint32_t _newMessageCount{0}; - bool _terminateConsumerThread{false}; - bool _flushingFinished{false}; + uint8_t *currentMemoryChunk{nullptr}; + Message *lastMessage{nullptr}; + uint32_t offset{0}; + uint32_t writtenMessageCountSnap{0}; + uint32_t newMessageCount{0}; + bool terminateConsumerThread{false}; + bool flushingFinished{false}; }; // A single-producer single-consumer circular buffer queue. @@ -126,9 +126,9 @@ public: static void freeChunksInFreeQueue(MessageQueue *const mainMessagesQueue) noexcept; inline void setImmediateMode(bool immediateMode) noexcept { _immediateMode = immediateMode; } - inline int getPendingMessageCount() const noexcept { return _writer._pendingMessageCount; } - inline int getWrittenMessageCount() const noexcept { return _writer._writtenMessageCount; } - inline int getNewMessageCount() const noexcept { return _reader._newMessageCount; } + inline int getPendingMessageCount() const noexcept { return _writer.pendingMessageCount; } + inline int getWrittenMessageCount() const noexcept { return _writer.writtenMessageCount; } + inline int getNewMessageCount() const noexcept { return _reader.newMessageCount; } private: class alignas(64) MemoryAllocator final { @@ -161,7 +161,7 @@ private: void pullMessages() noexcept; void executeMessages() noexcept; Message * readMessage() noexcept; - inline bool hasNewMessage() const noexcept { return _reader._newMessageCount > 0 && !_reader._flushingFinished; } + inline bool hasNewMessage() const noexcept { return _reader.newMessageCount > 0 && !_reader.flushingFinished; } void consumerThreadLoop() noexcept; WriterContext _writer; @@ -211,9 +211,9 @@ std::enable_if_t::value, T *> MessageQueue::allocate(uint32_t const count) noexcept { uint32_t allocatedSize = 0; T *const msg = reinterpret_cast(allocateImpl(allocatedSize, sizeof(T))); - msg->_next = reinterpret_cast(_writer._currentMemoryChunk + _writer._offset); - ++_writer._pendingMessageCount; - _writer._lastMessage = msg; + msg->_next = reinterpret_cast(_writer.currentMemoryChunk + _writer.offset); + ++_writer.pendingMessageCount; + _writer.lastMessage = msg; return msg; } @@ -224,7 +224,7 @@ MessageQueue::allocate(uint32_t const count) noexcept { assert(requestSize); uint32_t allocatedSize = 0; uint8_t *const allocatedMemory = allocateImpl(allocatedSize, requestSize); - _writer._lastMessage->_next = reinterpret_cast(_writer._currentMemoryChunk + _writer._offset); + _writer.lastMessage->_next = reinterpret_cast(_writer.currentMemoryChunk + _writer.offset); return reinterpret_cast(allocatedMemory); } diff --git a/native/cocos/bindings/auto/jsb_gfx_auto.cpp b/native/cocos/bindings/auto/jsb_gfx_auto.cpp index 8ec5a43bef..3b9d002666 100644 --- a/native/cocos/bindings/auto/jsb_gfx_auto.cpp +++ b/native/cocos/bindings/auto/jsb_gfx_auto.cpp @@ -596,33 +596,6 @@ static bool js_gfx_DeviceCaps_set_maxCubeMapTextureSize(se::State& s) } SE_BIND_PROP_SET(js_gfx_DeviceCaps_set_maxCubeMapTextureSize) -static bool js_gfx_DeviceCaps_get_uboOffsetAlignment(se::State& s) -{ - cc::gfx::DeviceCaps* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_DeviceCaps_get_uboOffsetAlignment : Invalid Native Object"); - - CC_UNUSED bool ok = true; - se::Value jsret; - ok &= nativevalue_to_se(cobj->uboOffsetAlignment, jsret, s.thisObject() /*ctx*/); - s.rval() = jsret; - SE_HOLD_RETURN_VALUE(cobj->uboOffsetAlignment, s.thisObject(), s.rval()); - return true; -} -SE_BIND_PROP_GET(js_gfx_DeviceCaps_get_uboOffsetAlignment) - -static bool js_gfx_DeviceCaps_set_uboOffsetAlignment(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::DeviceCaps* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_DeviceCaps_set_uboOffsetAlignment : Invalid Native Object"); - - CC_UNUSED bool ok = true; - ok &= sevalue_to_native(args[0], &cobj->uboOffsetAlignment, s.thisObject()); - SE_PRECONDITION2(ok, false, "js_gfx_DeviceCaps_set_uboOffsetAlignment : Error processing new value"); - return true; -} -SE_BIND_PROP_SET(js_gfx_DeviceCaps_set_uboOffsetAlignment) - static bool js_gfx_DeviceCaps_get_depthBits(se::State& s) { cc::gfx::DeviceCaps* cobj = SE_THIS_OBJECT(s); @@ -677,6 +650,33 @@ static bool js_gfx_DeviceCaps_set_stencilBits(se::State& s) } SE_BIND_PROP_SET(js_gfx_DeviceCaps_set_stencilBits) +static bool js_gfx_DeviceCaps_get_uboOffsetAlignment(se::State& s) +{ + cc::gfx::DeviceCaps* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_DeviceCaps_get_uboOffsetAlignment : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= nativevalue_to_se(cobj->uboOffsetAlignment, jsret, s.thisObject() /*ctx*/); + s.rval() = jsret; + SE_HOLD_RETURN_VALUE(cobj->uboOffsetAlignment, s.thisObject(), s.rval()); + return true; +} +SE_BIND_PROP_GET(js_gfx_DeviceCaps_get_uboOffsetAlignment) + +static bool js_gfx_DeviceCaps_set_uboOffsetAlignment(se::State& s) +{ + const auto& args = s.args(); + cc::gfx::DeviceCaps* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_gfx_DeviceCaps_set_uboOffsetAlignment : Invalid Native Object"); + + CC_UNUSED bool ok = true; + ok &= sevalue_to_native(args[0], &cobj->uboOffsetAlignment, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_gfx_DeviceCaps_set_uboOffsetAlignment : Error processing new value"); + return true; +} +SE_BIND_PROP_SET(js_gfx_DeviceCaps_set_uboOffsetAlignment) + static bool js_gfx_DeviceCaps_get_maxComputeSharedMemorySize(se::State& s) { cc::gfx::DeviceCaps* cobj = SE_THIS_OBJECT(s); @@ -931,10 +931,6 @@ bool sevalue_to_native(const se::Value &from, cc::gfx::DeviceCaps * to, se::Obje if(!field.isNullOrUndefined()) { ok &= sevalue_to_native(field, &(to->maxCubeMapTextureSize), ctx); } - json->getProperty("uboOffsetAlignment", &field); - if(!field.isNullOrUndefined()) { - ok &= sevalue_to_native(field, &(to->uboOffsetAlignment), ctx); - } json->getProperty("depthBits", &field); if(!field.isNullOrUndefined()) { ok &= sevalue_to_native(field, &(to->depthBits), ctx); @@ -943,6 +939,10 @@ bool sevalue_to_native(const se::Value &from, cc::gfx::DeviceCaps * to, se::Obje if(!field.isNullOrUndefined()) { ok &= sevalue_to_native(field, &(to->stencilBits), ctx); } + json->getProperty("uboOffsetAlignment", &field); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->uboOffsetAlignment), ctx); + } json->getProperty("maxComputeSharedMemorySize", &field); if(!field.isNullOrUndefined()) { ok &= sevalue_to_native(field, &(to->maxComputeSharedMemorySize), ctx); @@ -1049,13 +1049,13 @@ static bool js_gfx_DeviceCaps_constructor(se::State& s) ok &= sevalue_to_native(args[12], &(cobj->maxCubeMapTextureSize), nullptr); } if (argc > 13 && !args[13].isUndefined()) { - ok &= sevalue_to_native(args[13], &(cobj->uboOffsetAlignment), nullptr); + ok &= sevalue_to_native(args[13], &(cobj->depthBits), nullptr); } if (argc > 14 && !args[14].isUndefined()) { - ok &= sevalue_to_native(args[14], &(cobj->depthBits), nullptr); + ok &= sevalue_to_native(args[14], &(cobj->stencilBits), nullptr); } if (argc > 15 && !args[15].isUndefined()) { - ok &= sevalue_to_native(args[15], &(cobj->stencilBits), nullptr); + ok &= sevalue_to_native(args[15], &(cobj->uboOffsetAlignment), nullptr); } if (argc > 16 && !args[16].isUndefined()) { ok &= sevalue_to_native(args[16], &(cobj->maxComputeSharedMemorySize), nullptr); @@ -1128,9 +1128,9 @@ bool js_register_gfx_DeviceCaps(se::Object* obj) cls->defineProperty("maxUniformBlockSize", _SE(js_gfx_DeviceCaps_get_maxUniformBlockSize), _SE(js_gfx_DeviceCaps_set_maxUniformBlockSize)); cls->defineProperty("maxTextureSize", _SE(js_gfx_DeviceCaps_get_maxTextureSize), _SE(js_gfx_DeviceCaps_set_maxTextureSize)); cls->defineProperty("maxCubeMapTextureSize", _SE(js_gfx_DeviceCaps_get_maxCubeMapTextureSize), _SE(js_gfx_DeviceCaps_set_maxCubeMapTextureSize)); - cls->defineProperty("uboOffsetAlignment", _SE(js_gfx_DeviceCaps_get_uboOffsetAlignment), _SE(js_gfx_DeviceCaps_set_uboOffsetAlignment)); cls->defineProperty("depthBits", _SE(js_gfx_DeviceCaps_get_depthBits), _SE(js_gfx_DeviceCaps_set_depthBits)); cls->defineProperty("stencilBits", _SE(js_gfx_DeviceCaps_get_stencilBits), _SE(js_gfx_DeviceCaps_set_stencilBits)); + cls->defineProperty("uboOffsetAlignment", _SE(js_gfx_DeviceCaps_get_uboOffsetAlignment), _SE(js_gfx_DeviceCaps_set_uboOffsetAlignment)); cls->defineProperty("maxComputeSharedMemorySize", _SE(js_gfx_DeviceCaps_get_maxComputeSharedMemorySize), _SE(js_gfx_DeviceCaps_set_maxComputeSharedMemorySize)); cls->defineProperty("maxComputeWorkGroupInvocations", _SE(js_gfx_DeviceCaps_get_maxComputeWorkGroupInvocations), _SE(js_gfx_DeviceCaps_set_maxComputeWorkGroupInvocations)); cls->defineProperty("maxComputeWorkGroupSize", _SE(js_gfx_DeviceCaps_get_maxComputeWorkGroupSize), _SE(js_gfx_DeviceCaps_set_maxComputeWorkGroupSize)); @@ -14825,33 +14825,6 @@ static bool js_gfx_DeviceInfo_set_nativeHeight(se::State& s) } SE_BIND_PROP_SET(js_gfx_DeviceInfo_set_nativeHeight) -static bool js_gfx_DeviceInfo_get_sharedCtx(se::State& s) -{ - cc::gfx::DeviceInfo* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_DeviceInfo_get_sharedCtx : Invalid Native Object"); - - CC_UNUSED bool ok = true; - se::Value jsret; - ok &= nativevalue_to_se(cobj->sharedCtx, jsret, s.thisObject() /*ctx*/); - s.rval() = jsret; - SE_HOLD_RETURN_VALUE(cobj->sharedCtx, s.thisObject(), s.rval()); - return true; -} -SE_BIND_PROP_GET(js_gfx_DeviceInfo_get_sharedCtx) - -static bool js_gfx_DeviceInfo_set_sharedCtx(se::State& s) -{ - const auto& args = s.args(); - cc::gfx::DeviceInfo* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_DeviceInfo_set_sharedCtx : Invalid Native Object"); - - CC_UNUSED bool ok = true; - ok &= sevalue_to_native(args[0], &cobj->sharedCtx, s.thisObject()); - SE_PRECONDITION2(ok, false, "js_gfx_DeviceInfo_set_sharedCtx : Error processing new value"); - return true; -} -SE_BIND_PROP_SET(js_gfx_DeviceInfo_set_sharedCtx) - static bool js_gfx_DeviceInfo_get_bindingMappingInfo(se::State& s) { cc::gfx::DeviceInfo* cobj = SE_THIS_OBJECT(s); @@ -14912,10 +14885,6 @@ bool sevalue_to_native(const se::Value &from, cc::gfx::DeviceInfo * to, se::Obje if(!field.isNullOrUndefined()) { ok &= sevalue_to_native(field, &(to->nativeHeight), ctx); } - json->getProperty("sharedCtx", &field); - if(!field.isNullOrUndefined()) { - ok &= sevalue_to_native(field, &(to->sharedCtx), ctx); - } json->getProperty("bindingMappingInfo", &field); if(!field.isNullOrUndefined()) { ok &= sevalue_to_native(field, &(to->bindingMappingInfo), ctx); @@ -14974,10 +14943,7 @@ static bool js_gfx_DeviceInfo_constructor(se::State& s) ok &= sevalue_to_native(args[4], &(cobj->nativeHeight), nullptr); } if (argc > 5 && !args[5].isUndefined()) { - ok &= sevalue_to_native(args[5], &(cobj->sharedCtx), nullptr); - } - if (argc > 6 && !args[6].isUndefined()) { - ok &= sevalue_to_native(args[6], &(cobj->bindingMappingInfo), nullptr); + ok &= sevalue_to_native(args[5], &(cobj->bindingMappingInfo), nullptr); } if(!ok) { @@ -15021,7 +14987,6 @@ bool js_register_gfx_DeviceInfo(se::Object* obj) cls->defineProperty("height", _SE(js_gfx_DeviceInfo_get_height), _SE(js_gfx_DeviceInfo_set_height)); cls->defineProperty("nativeWidth", _SE(js_gfx_DeviceInfo_get_nativeWidth), _SE(js_gfx_DeviceInfo_set_nativeWidth)); cls->defineProperty("nativeHeight", _SE(js_gfx_DeviceInfo_get_nativeHeight), _SE(js_gfx_DeviceInfo_set_nativeHeight)); - cls->defineProperty("sharedCtx", _SE(js_gfx_DeviceInfo_get_sharedCtx), _SE(js_gfx_DeviceInfo_set_sharedCtx)); cls->defineProperty("bindingMappingInfo", _SE(js_gfx_DeviceInfo_get_bindingMappingInfo), _SE(js_gfx_DeviceInfo_set_bindingMappingInfo)); cls->defineFinalizeFunction(_SE(js_cc_gfx_DeviceInfo_finalize)); cls->install(); @@ -15783,10 +15748,7 @@ static bool js_gfx_CommandBuffer_initialize(se::State& s) HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_gfx_CommandBuffer_initialize : Error processing arguments"); - bool result = cobj->initialize(arg0.value()); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_CommandBuffer_initialize : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + cobj->initialize(arg0.value()); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); @@ -16142,25 +16104,6 @@ static bool js_gfx_Context_getDepthStencilFormat(se::State& s) } SE_BIND_PROP_GET(js_gfx_Context_getDepthStencilFormat) -static bool js_gfx_Context_getDevice(se::State& s) -{ - cc::gfx::Context* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_Context_getDevice : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 0) { - cc::gfx::Device* result = cobj->getDevice(); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_Context_getDevice : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); - return false; -} -SE_BIND_FUNC(js_gfx_Context_getDevice) - static bool js_gfx_Context_getSharedContext(se::State& s) { cc::gfx::Context* cobj = SE_THIS_OBJECT(s); @@ -16271,7 +16214,6 @@ bool js_register_gfx_Context(se::Object* obj) cls->defineProperty("colorFormat", _SE(js_gfx_Context_getColorFormat), nullptr); cls->defineProperty("depthStencilFormat", _SE(js_gfx_Context_getDepthStencilFormat), nullptr); cls->defineFunction("destroy", _SE(js_gfx_Context_destroy)); - cls->defineFunction("getDevice", _SE(js_gfx_Context_getDevice)); cls->defineFunction("initialize", _SE(js_gfx_Context_initialize)); cls->defineFunction("present", _SE(js_gfx_Context_present)); cls->defineFinalizeFunction(_SE(js_cc_gfx_Context_finalize)); @@ -16650,10 +16592,7 @@ static bool js_gfx_DescriptorSet_initialize(se::State& s) HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_initialize : Error processing arguments"); - bool result = cobj->initialize(arg0.value()); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSet_initialize : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + cobj->initialize(arg0.value()); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); @@ -16797,10 +16736,7 @@ static bool js_gfx_DescriptorSetLayout_initialize(se::State& s) HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSetLayout_initialize : Error processing arguments"); - bool result = cobj->initialize(arg0.value()); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_DescriptorSetLayout_initialize : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + cobj->initialize(arg0.value()); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); @@ -16940,10 +16876,7 @@ static bool js_gfx_Framebuffer_initialize(se::State& s) HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_gfx_Framebuffer_initialize : Error processing arguments"); - bool result = cobj->initialize(arg0.value()); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_Framebuffer_initialize : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + cobj->initialize(arg0.value()); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); @@ -17065,12 +16998,7 @@ SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_GlobalBarrier_finalize) static bool js_gfx_GlobalBarrier_constructor(se::State& s) // constructor.c { - CC_UNUSED bool ok = true; - const auto& args = s.args(); - cc::gfx::Device* arg0 = nullptr; - ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); - SE_PRECONDITION2(ok, false, "js_gfx_GlobalBarrier_constructor : Error processing arguments"); - cc::gfx::GlobalBarrier* cobj = JSB_ALLOC(cc::gfx::GlobalBarrier, arg0); + cc::gfx::GlobalBarrier* cobj = JSB_ALLOC(cc::gfx::GlobalBarrier); s.thisObject()->setPrivateData(cobj); se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); return true; @@ -17368,10 +17296,7 @@ static bool js_gfx_InputAssembler_initialize(se::State& s) HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_gfx_InputAssembler_initialize : Error processing arguments"); - bool result = cobj->initialize(arg0.value()); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_InputAssembler_initialize : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + cobj->initialize(arg0.value()); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); @@ -17616,10 +17541,7 @@ static bool js_gfx_PipelineLayout_initialize(se::State& s) HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_gfx_PipelineLayout_initialize : Error processing arguments"); - bool result = cobj->initialize(arg0.value()); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineLayout_initialize : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + cobj->initialize(arg0.value()); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); @@ -17891,10 +17813,7 @@ static bool js_gfx_PipelineState_initialize(se::State& s) HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_initialize : Error processing arguments"); - bool result = cobj->initialize(arg0.value()); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_PipelineState_initialize : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + cobj->initialize(arg0.value()); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); @@ -18004,10 +17923,7 @@ static bool js_gfx_Queue_initialize(se::State& s) HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_gfx_Queue_initialize : Error processing arguments"); - bool result = cobj->initialize(arg0.value()); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_Queue_initialize : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + cobj->initialize(arg0.value()); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); @@ -18166,10 +18082,7 @@ static bool js_gfx_RenderPass_initialize(se::State& s) HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_gfx_RenderPass_initialize : Error processing arguments"); - bool result = cobj->initialize(arg0.value()); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_RenderPass_initialize : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + cobj->initialize(arg0.value()); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); @@ -18464,10 +18377,7 @@ static bool js_gfx_Sampler_initialize(se::State& s) HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_gfx_Sampler_initialize : Error processing arguments"); - bool result = cobj->initialize(arg0.value()); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_Sampler_initialize : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + cobj->initialize(arg0.value()); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); @@ -18767,10 +18677,7 @@ static bool js_gfx_Shader_initialize(se::State& s) HolderType arg0 = {}; ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); SE_PRECONDITION2(ok, false, "js_gfx_Shader_initialize : Error processing arguments"); - bool result = cobj->initialize(arg0.value()); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_Shader_initialize : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + cobj->initialize(arg0.value()); return true; } SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); @@ -18851,25 +18758,6 @@ static bool js_gfx_Texture_destroy(se::State& s) } SE_BIND_FUNC(js_gfx_Texture_destroy) -static bool js_gfx_Texture_getBuffer(se::State& s) -{ - cc::gfx::Texture* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_Texture_getBuffer : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 0) { - unsigned char* result = cobj->getBuffer(); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_Texture_getBuffer : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); - return false; -} -SE_BIND_PROP_GET(js_gfx_Texture_getBuffer) - static bool js_gfx_Texture_getDepth(se::State& s) { cc::gfx::Texture* cobj = SE_THIS_OBJECT(s); @@ -19191,7 +19079,6 @@ bool js_register_gfx_Texture(se::Object* obj) cls->defineProperty("samples", _SE(js_gfx_Texture_getSamples), nullptr); cls->defineProperty("format", _SE(js_gfx_Texture_getFormat), nullptr); - cls->defineProperty("buffer", _SE(js_gfx_Texture_getBuffer), nullptr); cls->defineProperty("levelCount", _SE(js_gfx_Texture_getLevelCount), nullptr); cls->defineProperty("height", _SE(js_gfx_Texture_getHeight), nullptr); cls->defineProperty("width", _SE(js_gfx_Texture_getWidth), nullptr); @@ -19263,12 +19150,7 @@ SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_TextureBarrier_finalize) static bool js_gfx_TextureBarrier_constructor(se::State& s) // constructor.c { - CC_UNUSED bool ok = true; - const auto& args = s.args(); - cc::gfx::Device* arg0 = nullptr; - ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); - SE_PRECONDITION2(ok, false, "js_gfx_TextureBarrier_constructor : Error processing arguments"); - cc::gfx::TextureBarrier* cobj = JSB_ALLOC(cc::gfx::TextureBarrier, arg0); + cc::gfx::TextureBarrier* cobj = JSB_ALLOC(cc::gfx::TextureBarrier); s.thisObject()->setPrivateData(cobj); se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); return true; @@ -19713,25 +19595,6 @@ static bool js_gfx_Device_getCommandBuffer(se::State& s) } SE_BIND_PROP_GET(js_gfx_Device_getCommandBuffer) -static bool js_gfx_Device_getContext(se::State& s) -{ - cc::gfx::Device* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gfx_Device_getContext : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 0) { - cc::gfx::Context* result = cobj->getContext(); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gfx_Device_getContext : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); - return false; -} -SE_BIND_PROP_GET(js_gfx_Device_getContext) - static bool js_gfx_Device_getDepthStencilFormat(se::State& s) { cc::gfx::Device* cobj = SE_THIS_OBJECT(s); @@ -20137,7 +20000,6 @@ bool js_register_gfx_Device(se::Object* obj) cls->defineProperty("queue", _SE(js_gfx_Device_getQueue), nullptr); cls->defineProperty("width", _SE(js_gfx_Device_getWidth), nullptr); cls->defineProperty("renderer", _SE(js_gfx_Device_getRenderer), nullptr); - cls->defineProperty("context", _SE(js_gfx_Device_getContext), nullptr); cls->defineProperty("commandBuffer", _SE(js_gfx_Device_getCommandBuffer), nullptr); cls->defineProperty("vendor", _SE(js_gfx_Device_getVendor), nullptr); cls->defineProperty("surfaceTransform", _SE(js_gfx_Device_getSurfaceTransform), nullptr); diff --git a/native/cocos/bindings/auto/jsb_gfx_auto.h b/native/cocos/bindings/auto/jsb_gfx_auto.h index 674a7604e7..04f82a6b20 100644 --- a/native/cocos/bindings/auto/jsb_gfx_auto.h +++ b/native/cocos/bindings/auto/jsb_gfx_auto.h @@ -624,7 +624,6 @@ bool register_all_gfx(se::Object* obj); JSB_REGISTER_OBJECT_TYPE(cc::gfx::Context); SE_DECLARE_FUNC(js_gfx_Context_destroy); -SE_DECLARE_FUNC(js_gfx_Context_getDevice); SE_DECLARE_FUNC(js_gfx_Context_initialize); SE_DECLARE_FUNC(js_gfx_Context_present); SE_DECLARE_FUNC(js_gfx_Context_Context); diff --git a/native/cocos/bindings/auto/jsb_gles2_auto.cpp b/native/cocos/bindings/auto/jsb_gles2_auto.cpp deleted file mode 100644 index 3f8b310fd1..0000000000 --- a/native/cocos/bindings/auto/jsb_gles2_auto.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - Copyright (c) 2019-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. -****************************************************************************/ - -#include "cocos/bindings/auto/jsb_gles2_auto.h" -#include "cocos/bindings/manual/jsb_conversions.h" -#include "cocos/bindings/manual/jsb_global.h" -#include "renderer/gfx-gles2/GFXGLES2.h" - -#ifndef JSB_ALLOC -#define JSB_ALLOC(kls, ...) new (std::nothrow) kls(__VA_ARGS__) -#endif - -#ifndef JSB_FREE -#define JSB_FREE(ptr) delete ptr -#endif -se::Object* __jsb_cc_gfx_GLES2Device_proto = nullptr; -se::Class* __jsb_cc_gfx_GLES2Device_class = nullptr; - -SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_GLES2Device_finalize) - -static bool js_gles2_GLES2Device_constructor(se::State& s) // constructor.c -{ - cc::gfx::GLES2Device* cobj = JSB_ALLOC(cc::gfx::GLES2Device); - s.thisObject()->setPrivateData(cobj); - se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); - return true; -} -SE_BIND_CTOR(js_gles2_GLES2Device_constructor, __jsb_cc_gfx_GLES2Device_class, js_cc_gfx_GLES2Device_finalize) - - - -extern se::Object* __jsb_cc_gfx_Device_proto; - -static bool js_cc_gfx_GLES2Device_finalize(se::State& s) -{ - auto iter = se::NonRefNativePtrCreatedByCtorMap::find(SE_THIS_OBJECT(s)); - if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) - { - se::NonRefNativePtrCreatedByCtorMap::erase(iter); - cc::gfx::GLES2Device* cobj = SE_THIS_OBJECT(s); - JSB_FREE(cobj); - } - return true; -} -SE_BIND_FINALIZE_FUNC(js_cc_gfx_GLES2Device_finalize) - -bool js_register_gles2_GLES2Device(se::Object* obj) -{ - auto cls = se::Class::create("GLES2Device", obj, __jsb_cc_gfx_Device_proto, _SE(js_gles2_GLES2Device_constructor)); - - cls->defineFinalizeFunction(_SE(js_cc_gfx_GLES2Device_finalize)); - cls->install(); - JSBClassType::registerClass(cls); - - __jsb_cc_gfx_GLES2Device_proto = cls->getProto(); - __jsb_cc_gfx_GLES2Device_class = cls; - - se::ScriptEngine::getInstance()->clearException(); - return true; -} - -bool register_all_gles2(se::Object* obj) -{ - // Get the ns - se::Value nsVal; - if (!obj->getProperty("gfx", &nsVal)) - { - se::HandleObject jsobj(se::Object::createPlainObject()); - nsVal.setObject(jsobj); - obj->setProperty("gfx", nsVal); - } - se::Object* ns = nsVal.toObject(); - - js_register_gles2_GLES2Device(ns); - return true; -} - diff --git a/native/cocos/bindings/auto/jsb_gles2_auto.h b/native/cocos/bindings/auto/jsb_gles2_auto.h deleted file mode 100644 index 4c309e74ca..0000000000 --- a/native/cocos/bindings/auto/jsb_gles2_auto.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - Copyright (c) 2019-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 "base/Config.h" -#include -#include "cocos/bindings/jswrapper/SeApi.h" -#include "cocos/bindings/manual/jsb_conversions.h" -#include "cocos/renderer/gfx-gles2/GFXGLES2.h" - -extern se::Object* __jsb_cc_gfx_GLES2Device_proto; -extern se::Class* __jsb_cc_gfx_GLES2Device_class; - -bool js_register_cc_gfx_GLES2Device(se::Object* obj); -bool register_all_gles2(se::Object* obj); - -JSB_REGISTER_OBJECT_TYPE(cc::gfx::GLES2Device); -SE_DECLARE_FUNC(js_gles2_GLES2Device_GLES2Device); - diff --git a/native/cocos/bindings/auto/jsb_gles3_auto.cpp b/native/cocos/bindings/auto/jsb_gles3_auto.cpp deleted file mode 100644 index a8f0154cb4..0000000000 --- a/native/cocos/bindings/auto/jsb_gles3_auto.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** - Copyright (c) 2019-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. -****************************************************************************/ - -#include "cocos/bindings/auto/jsb_gles3_auto.h" -#include "cocos/bindings/manual/jsb_conversions.h" -#include "cocos/bindings/manual/jsb_global.h" -#include "renderer/gfx-gles3/GFXGLES3.h" - -#ifndef JSB_ALLOC -#define JSB_ALLOC(kls, ...) new (std::nothrow) kls(__VA_ARGS__) -#endif - -#ifndef JSB_FREE -#define JSB_FREE(ptr) delete ptr -#endif -se::Object* __jsb_cc_gfx_GLES3Device_proto = nullptr; -se::Class* __jsb_cc_gfx_GLES3Device_class = nullptr; - -static bool js_gles3_GLES3Device_getMinorVersion(se::State& s) -{ - cc::gfx::GLES3Device* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_gles3_GLES3Device_getMinorVersion : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 0) { - unsigned int result = cobj->getMinorVersion(); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_gles3_GLES3Device_getMinorVersion : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); - return false; -} -SE_BIND_FUNC(js_gles3_GLES3Device_getMinorVersion) - -SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_GLES3Device_finalize) - -static bool js_gles3_GLES3Device_constructor(se::State& s) // constructor.c -{ - cc::gfx::GLES3Device* cobj = JSB_ALLOC(cc::gfx::GLES3Device); - s.thisObject()->setPrivateData(cobj); - se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); - return true; -} -SE_BIND_CTOR(js_gles3_GLES3Device_constructor, __jsb_cc_gfx_GLES3Device_class, js_cc_gfx_GLES3Device_finalize) - - - -extern se::Object* __jsb_cc_gfx_Device_proto; - -static bool js_cc_gfx_GLES3Device_finalize(se::State& s) -{ - auto iter = se::NonRefNativePtrCreatedByCtorMap::find(SE_THIS_OBJECT(s)); - if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) - { - se::NonRefNativePtrCreatedByCtorMap::erase(iter); - cc::gfx::GLES3Device* cobj = SE_THIS_OBJECT(s); - JSB_FREE(cobj); - } - return true; -} -SE_BIND_FINALIZE_FUNC(js_cc_gfx_GLES3Device_finalize) - -bool js_register_gles3_GLES3Device(se::Object* obj) -{ - auto cls = se::Class::create("GLES3Device", obj, __jsb_cc_gfx_Device_proto, _SE(js_gles3_GLES3Device_constructor)); - - cls->defineFunction("getMinorVersion", _SE(js_gles3_GLES3Device_getMinorVersion)); - cls->defineFinalizeFunction(_SE(js_cc_gfx_GLES3Device_finalize)); - cls->install(); - JSBClassType::registerClass(cls); - - __jsb_cc_gfx_GLES3Device_proto = cls->getProto(); - __jsb_cc_gfx_GLES3Device_class = cls; - - se::ScriptEngine::getInstance()->clearException(); - return true; -} - -bool register_all_gles3(se::Object* obj) -{ - // Get the ns - se::Value nsVal; - if (!obj->getProperty("gfx", &nsVal)) - { - se::HandleObject jsobj(se::Object::createPlainObject()); - nsVal.setObject(jsobj); - obj->setProperty("gfx", nsVal); - } - se::Object* ns = nsVal.toObject(); - - js_register_gles3_GLES3Device(ns); - return true; -} - diff --git a/native/cocos/bindings/auto/jsb_gles3_auto.h b/native/cocos/bindings/auto/jsb_gles3_auto.h deleted file mode 100644 index 64f07379ba..0000000000 --- a/native/cocos/bindings/auto/jsb_gles3_auto.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - Copyright (c) 2019-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 "base/Config.h" -#include -#include "cocos/bindings/jswrapper/SeApi.h" -#include "cocos/bindings/manual/jsb_conversions.h" -#include "cocos/renderer/gfx-gles3/GFXGLES3.h" - -extern se::Object* __jsb_cc_gfx_GLES3Device_proto; -extern se::Class* __jsb_cc_gfx_GLES3Device_class; - -bool js_register_cc_gfx_GLES3Device(se::Object* obj); -bool register_all_gles3(se::Object* obj); - -JSB_REGISTER_OBJECT_TYPE(cc::gfx::GLES3Device); -SE_DECLARE_FUNC(js_gles3_GLES3Device_getMinorVersion); -SE_DECLARE_FUNC(js_gles3_GLES3Device_GLES3Device); - diff --git a/native/cocos/bindings/auto/jsb_mtl_auto.cpp b/native/cocos/bindings/auto/jsb_mtl_auto.cpp deleted file mode 100644 index ce676c461e..0000000000 --- a/native/cocos/bindings/auto/jsb_mtl_auto.cpp +++ /dev/null @@ -1,191 +0,0 @@ -/**************************************************************************** - Copyright (c) 2019-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. -****************************************************************************/ - -#include "cocos/bindings/auto/jsb_mtl_auto.h" -#include "cocos/bindings/manual/jsb_conversions.h" -#include "cocos/bindings/manual/jsb_global.h" -#include "renderer/gfx-metal/GFXMTL.h" - -#ifndef JSB_ALLOC -#define JSB_ALLOC(kls, ...) new (std::nothrow) kls(__VA_ARGS__) -#endif - -#ifndef JSB_FREE -#define JSB_FREE(ptr) delete ptr -#endif -se::Object* __jsb_cc_gfx_CCMTLDevice_proto = nullptr; -se::Class* __jsb_cc_gfx_CCMTLDevice_class = nullptr; - -static bool js_mtl_CCMTLDevice_disposeCurrentDrawable(se::State& s) -{ - cc::gfx::CCMTLDevice* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_mtl_CCMTLDevice_disposeCurrentDrawable : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - if (argc == 0) { - cobj->disposeCurrentDrawable(); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); - return false; -} -SE_BIND_FUNC(js_mtl_CCMTLDevice_disposeCurrentDrawable) - -static bool js_mtl_CCMTLDevice_getCurrentDrawable(se::State& s) -{ - cc::gfx::CCMTLDevice* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_mtl_CCMTLDevice_getCurrentDrawable : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 0) { - void* result = cobj->getCurrentDrawable(); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_mtl_CCMTLDevice_getCurrentDrawable : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); - return false; -} -SE_BIND_FUNC(js_mtl_CCMTLDevice_getCurrentDrawable) - -static bool js_mtl_CCMTLDevice_getDSSTexture(se::State& s) -{ - cc::gfx::CCMTLDevice* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_mtl_CCMTLDevice_getDSSTexture : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 0) { - void* result = cobj->getDSSTexture(); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_mtl_CCMTLDevice_getDSSTexture : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); - return false; -} -SE_BIND_FUNC(js_mtl_CCMTLDevice_getDSSTexture) - -static bool js_mtl_CCMTLDevice_getMTLLayer(se::State& s) -{ - cc::gfx::CCMTLDevice* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_mtl_CCMTLDevice_getMTLLayer : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc == 0) { - void* result = cobj->getMTLLayer(); - ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); - SE_PRECONDITION2(ok, false, "js_mtl_CCMTLDevice_getMTLLayer : Error processing arguments"); - SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); - return false; -} -SE_BIND_FUNC(js_mtl_CCMTLDevice_getMTLLayer) - -static bool js_mtl_CCMTLDevice_onPresentCompleted(se::State& s) -{ - cc::gfx::CCMTLDevice* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_mtl_CCMTLDevice_onPresentCompleted : Invalid Native Object"); - const auto& args = s.args(); - size_t argc = args.size(); - if (argc == 0) { - cobj->onPresentCompleted(); - return true; - } - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); - return false; -} -SE_BIND_FUNC(js_mtl_CCMTLDevice_onPresentCompleted) - -SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_CCMTLDevice_finalize) - -static bool js_mtl_CCMTLDevice_constructor(se::State& s) // constructor.c -{ - cc::gfx::CCMTLDevice* cobj = JSB_ALLOC(cc::gfx::CCMTLDevice); - s.thisObject()->setPrivateData(cobj); - se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); - return true; -} -SE_BIND_CTOR(js_mtl_CCMTLDevice_constructor, __jsb_cc_gfx_CCMTLDevice_class, js_cc_gfx_CCMTLDevice_finalize) - - - -extern se::Object* __jsb_cc_gfx_Device_proto; - -static bool js_cc_gfx_CCMTLDevice_finalize(se::State& s) -{ - auto iter = se::NonRefNativePtrCreatedByCtorMap::find(SE_THIS_OBJECT(s)); - if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) - { - se::NonRefNativePtrCreatedByCtorMap::erase(iter); - cc::gfx::CCMTLDevice* cobj = SE_THIS_OBJECT(s); - JSB_FREE(cobj); - } - return true; -} -SE_BIND_FINALIZE_FUNC(js_cc_gfx_CCMTLDevice_finalize) - -bool js_register_mtl_CCMTLDevice(se::Object* obj) -{ - auto cls = se::Class::create("CCMTLDevice", obj, __jsb_cc_gfx_Device_proto, _SE(js_mtl_CCMTLDevice_constructor)); - - cls->defineFunction("disposeCurrentDrawable", _SE(js_mtl_CCMTLDevice_disposeCurrentDrawable)); - cls->defineFunction("getCurrentDrawable", _SE(js_mtl_CCMTLDevice_getCurrentDrawable)); - cls->defineFunction("getDSSTexture", _SE(js_mtl_CCMTLDevice_getDSSTexture)); - cls->defineFunction("getMTLLayer", _SE(js_mtl_CCMTLDevice_getMTLLayer)); - cls->defineFunction("onPresentCompleted", _SE(js_mtl_CCMTLDevice_onPresentCompleted)); - cls->defineFinalizeFunction(_SE(js_cc_gfx_CCMTLDevice_finalize)); - cls->install(); - JSBClassType::registerClass(cls); - - __jsb_cc_gfx_CCMTLDevice_proto = cls->getProto(); - __jsb_cc_gfx_CCMTLDevice_class = cls; - - se::ScriptEngine::getInstance()->clearException(); - return true; -} - -bool register_all_mtl(se::Object* obj) -{ - // Get the ns - se::Value nsVal; - if (!obj->getProperty("gfx", &nsVal)) - { - se::HandleObject jsobj(se::Object::createPlainObject()); - nsVal.setObject(jsobj); - obj->setProperty("gfx", nsVal); - } - se::Object* ns = nsVal.toObject(); - - js_register_mtl_CCMTLDevice(ns); - return true; -} - diff --git a/native/cocos/bindings/auto/jsb_mtl_auto.h b/native/cocos/bindings/auto/jsb_mtl_auto.h deleted file mode 100644 index be0cecc60d..0000000000 --- a/native/cocos/bindings/auto/jsb_mtl_auto.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** - Copyright (c) 2019-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 "base/Config.h" -#include -#include "cocos/bindings/jswrapper/SeApi.h" -#include "cocos/bindings/manual/jsb_conversions.h" -#include "cocos/renderer/gfx-metal/GFXMTL.h" - -extern se::Object* __jsb_cc_gfx_CCMTLDevice_proto; -extern se::Class* __jsb_cc_gfx_CCMTLDevice_class; - -bool js_register_cc_gfx_CCMTLDevice(se::Object* obj); -bool register_all_mtl(se::Object* obj); - -JSB_REGISTER_OBJECT_TYPE(cc::gfx::CCMTLDevice); -SE_DECLARE_FUNC(js_mtl_CCMTLDevice_disposeCurrentDrawable); -SE_DECLARE_FUNC(js_mtl_CCMTLDevice_getCurrentDrawable); -SE_DECLARE_FUNC(js_mtl_CCMTLDevice_getDSSTexture); -SE_DECLARE_FUNC(js_mtl_CCMTLDevice_getMTLLayer); -SE_DECLARE_FUNC(js_mtl_CCMTLDevice_onPresentCompleted); -SE_DECLARE_FUNC(js_mtl_CCMTLDevice_CCMTLDevice); - diff --git a/native/cocos/bindings/auto/jsb_vk_auto.cpp b/native/cocos/bindings/auto/jsb_vk_auto.cpp deleted file mode 100644 index cd7214bb37..0000000000 --- a/native/cocos/bindings/auto/jsb_vk_auto.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** - Copyright (c) 2019-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. -****************************************************************************/ - -#include "cocos/bindings/auto/jsb_vk_auto.h" -#include "cocos/bindings/manual/jsb_conversions.h" -#include "cocos/bindings/manual/jsb_global.h" -#include "renderer/gfx-vulkan/GFXVulkan.h" - -#ifndef JSB_ALLOC -#define JSB_ALLOC(kls, ...) new (std::nothrow) kls(__VA_ARGS__) -#endif - -#ifndef JSB_FREE -#define JSB_FREE(ptr) delete ptr -#endif -se::Object* __jsb_cc_gfx_CCVKDevice_proto = nullptr; -se::Class* __jsb_cc_gfx_CCVKDevice_class = nullptr; - -SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_CCVKDevice_finalize) - -static bool js_vk_CCVKDevice_constructor(se::State& s) // constructor.c -{ - cc::gfx::CCVKDevice* cobj = JSB_ALLOC(cc::gfx::CCVKDevice); - s.thisObject()->setPrivateData(cobj); - se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); - return true; -} -SE_BIND_CTOR(js_vk_CCVKDevice_constructor, __jsb_cc_gfx_CCVKDevice_class, js_cc_gfx_CCVKDevice_finalize) - - - -extern se::Object* __jsb_cc_gfx_Device_proto; - -static bool js_cc_gfx_CCVKDevice_finalize(se::State& s) -{ - auto iter = se::NonRefNativePtrCreatedByCtorMap::find(SE_THIS_OBJECT(s)); - if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) - { - se::NonRefNativePtrCreatedByCtorMap::erase(iter); - cc::gfx::CCVKDevice* cobj = SE_THIS_OBJECT(s); - JSB_FREE(cobj); - } - return true; -} -SE_BIND_FINALIZE_FUNC(js_cc_gfx_CCVKDevice_finalize) - -bool js_register_vk_CCVKDevice(se::Object* obj) -{ - auto cls = se::Class::create("CCVKDevice", obj, __jsb_cc_gfx_Device_proto, _SE(js_vk_CCVKDevice_constructor)); - - cls->defineFinalizeFunction(_SE(js_cc_gfx_CCVKDevice_finalize)); - cls->install(); - JSBClassType::registerClass(cls); - - __jsb_cc_gfx_CCVKDevice_proto = cls->getProto(); - __jsb_cc_gfx_CCVKDevice_class = cls; - - se::ScriptEngine::getInstance()->clearException(); - return true; -} - -bool register_all_vk(se::Object* obj) -{ - // Get the ns - se::Value nsVal; - if (!obj->getProperty("gfx", &nsVal)) - { - se::HandleObject jsobj(se::Object::createPlainObject()); - nsVal.setObject(jsobj); - obj->setProperty("gfx", nsVal); - } - se::Object* ns = nsVal.toObject(); - - js_register_vk_CCVKDevice(ns); - return true; -} - diff --git a/native/cocos/bindings/auto/jsb_vk_auto.h b/native/cocos/bindings/auto/jsb_vk_auto.h deleted file mode 100644 index 98fc6aa67b..0000000000 --- a/native/cocos/bindings/auto/jsb_vk_auto.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - Copyright (c) 2019-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 "base/Config.h" -#include -#include "cocos/bindings/jswrapper/SeApi.h" -#include "cocos/bindings/manual/jsb_conversions.h" -#include "cocos/renderer/gfx-vulkan/GFXVulkan.h" - -extern se::Object* __jsb_cc_gfx_CCVKDevice_proto; -extern se::Class* __jsb_cc_gfx_CCVKDevice_class; - -bool js_register_cc_gfx_CCVKDevice(se::Object* obj); -bool register_all_vk(se::Object* obj); - -JSB_REGISTER_OBJECT_TYPE(cc::gfx::CCVKDevice); -SE_DECLARE_FUNC(js_vk_CCVKDevice_CCVKDevice); - diff --git a/native/cocos/bindings/event/EventDispatcher.cpp b/native/cocos/bindings/event/EventDispatcher.cpp index 9c6a7d2593..bbfcd62b80 100644 --- a/native/cocos/bindings/event/EventDispatcher.cpp +++ b/native/cocos/bindings/event/EventDispatcher.cpp @@ -94,7 +94,7 @@ void EventDispatcher::dispatchTouchEvent(const struct TouchEvent &touchEvent) { _jsTouchObjArray->root(); } - _jsTouchObjArray->setProperty("length", se::Value(touchEvent.touches.size())); + _jsTouchObjArray->setProperty("length", se::Value((uint32_t)touchEvent.touches.size())); while (_jsTouchObjPool.size() < touchEvent.touches.size()) { se::Object *touchObj = se::Object::createPlainObject(); diff --git a/native/cocos/bindings/manual/jsb_gfx_agent.cpp b/native/cocos/bindings/manual/jsb_gfx_agent.cpp deleted file mode 100644 index 1b9436e9ec..0000000000 --- a/native/cocos/bindings/manual/jsb_gfx_agent.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** - Copyright (c) 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. -****************************************************************************/ - -#include "cocos/bindings/manual/jsb_gfx_agent.h" -#include "cocos/bindings/manual/jsb_conversions.h" -#include "cocos/bindings/manual/jsb_global.h" -#include "gfx-agent/GFXDeviceAgent.h" - -#ifndef JSB_ALLOC -#define JSB_ALLOC(kls, ...) new (std::nothrow) kls(__VA_ARGS__) -#endif - -#ifndef JSB_FREE -#define JSB_FREE(ptr) delete ptr -#endif -se::Object* __jsb_cc_gfx_DeviceAgent_proto = nullptr; -se::Class* __jsb_cc_gfx_DeviceAgent_class = nullptr; - -SE_DECLARE_FINALIZE_FUNC(js_cc_gfx_DeviceAgent_finalize) - -static bool js_gfx_agent_DeviceAgent_constructor(se::State& s) // constructor.c -{ - CC_UNUSED bool ok = true; - const auto& args = s.args(); - cc::gfx::Device* arg0 = nullptr; - ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); - SE_PRECONDITION2(ok, false, "js_gfx_agent_DeviceAgent_constructor : Error processing arguments"); - cc::gfx::DeviceAgent* cobj = JSB_ALLOC(cc::gfx::DeviceAgent, arg0); - s.thisObject()->setPrivateData(cobj); - args[0].toObject()->clearPrivateData(true); // actor device is now under agent's full control (unique_ptr) - se::NonRefNativePtrCreatedByCtorMap::emplace(cobj); - return true; -} -SE_BIND_CTOR(js_gfx_agent_DeviceAgent_constructor, __jsb_cc_gfx_DeviceAgent_class, js_cc_gfx_DeviceAgent_finalize) - - - -extern se::Object* __jsb_cc_gfx_Device_proto; - -static bool js_cc_gfx_DeviceAgent_finalize(se::State& s) -{ - auto iter = se::NonRefNativePtrCreatedByCtorMap::find(SE_THIS_OBJECT(s)); - if (iter != se::NonRefNativePtrCreatedByCtorMap::end()) - { - se::NonRefNativePtrCreatedByCtorMap::erase(iter); - cc::gfx::DeviceAgent* cobj = SE_THIS_OBJECT(s); - // device destruction should happen after all resources which we have no way to control through JS object lifecycles - //JSB_FREE(cobj); // so just skip it here and do it manually - } - return true; -} -SE_BIND_FINALIZE_FUNC(js_cc_gfx_DeviceAgent_finalize) - -bool js_register_gfx_agent_DeviceAgent(se::Object* obj) -{ - auto cls = se::Class::create("DeviceAgent", obj, __jsb_cc_gfx_Device_proto, _SE(js_gfx_agent_DeviceAgent_constructor)); - - cls->defineFinalizeFunction(_SE(js_cc_gfx_DeviceAgent_finalize)); - cls->install(); - JSBClassType::registerClass(cls); - - __jsb_cc_gfx_DeviceAgent_proto = cls->getProto(); - __jsb_cc_gfx_DeviceAgent_class = cls; - - se::ScriptEngine::getInstance()->clearException(); - return true; -} - -bool register_all_gfx_agent(se::Object* obj) -{ - // Get the ns - se::Value nsVal; - if (!obj->getProperty("gfx", &nsVal)) - { - se::HandleObject jsobj(se::Object::createPlainObject()); - nsVal.setObject(jsobj); - obj->setProperty("gfx", nsVal); - } - se::Object* ns = nsVal.toObject(); - - js_register_gfx_agent_DeviceAgent(ns); - return true; -} diff --git a/native/cocos/bindings/manual/jsb_gfx_agent.h b/native/cocos/bindings/manual/jsb_gfx_agent.h deleted file mode 100644 index 1bef9079e0..0000000000 --- a/native/cocos/bindings/manual/jsb_gfx_agent.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - Copyright (c) 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 "base/Config.h" -#include "base/CoreStd.h" -#include "bindings/auto/jsb_gfx_auto.h" -#include "bindings/jswrapper/SeApi.h" -#include "bindings/manual/jsb_conversions.h" -#include "gfx-agent/GFXDeviceAgent.h" -#include "gfx-base/GFXDef.h" -#include - -extern se::Object *__jsb_cc_gfx_DeviceAgent_proto; -extern se::Class * __jsb_cc_gfx_DeviceAgent_class; - -bool js_register_cc_gfx_DeviceAgent(se::Object *obj); -bool register_all_gfx_agent(se::Object *obj); - -JSB_REGISTER_OBJECT_TYPE(cc::gfx::DeviceAgent); -SE_DECLARE_FUNC(js_gfx_agent_DeviceAgent_DeviceAgent); diff --git a/native/cocos/bindings/manual/jsb_gfx_manual.cpp b/native/cocos/bindings/manual/jsb_gfx_manual.cpp index 50a29c9e75..4bd06120ef 100644 --- a/native/cocos/bindings/manual/jsb_gfx_manual.cpp +++ b/native/cocos/bindings/manual/jsb_gfx_manual.cpp @@ -29,36 +29,9 @@ #include "bindings/manual/jsb_conversions.h" #include "bindings/manual/jsb_global.h" -#ifdef CC_USE_VULKAN - #include "bindings/auto/jsb_vk_auto.h" - #include "gfx-vulkan/GFXVulkan.h" -#endif - -#ifdef CC_USE_METAL - #include "bindings/auto/jsb_mtl_auto.h" - #include "gfx-metal/GFXMTL.h" -#endif - -#ifdef CC_USE_GLES3 - #include "bindings/auto/jsb_gles3_auto.h" - #include "gfx-gles3/GFXGLES3.h" -#endif - -#ifdef CC_USE_GLES2 - #include "bindings/auto/jsb_gles2_auto.h" - #include "gfx-gles2/GFXGLES2.h" -#endif - #include #include -#define GFX_MAX_VERTEX_ATTRIBUTES 16 -#define GFX_MAX_TEXTURE_UNITS 16 -#define GFX_MAX_ATTACHMENTS 4 -#define GFX_MAX_BUFFER_BINDINGS 24 -#define GFX_INVALID_BINDING ((uint8_t)-1) -#define GFX_INVALID_HANDLE ((uint)-1) - bool js_gfx_Device_copyBuffersToTexture(se::State &s) { cc::gfx::Device *cobj = (cc::gfx::Device *)s.nativeThisObject(); SE_PRECONDITION2(cobj, false, "js_gfx_Device_copyBuffersToTexture : Invalid Native Object"); @@ -238,10 +211,10 @@ static bool js_gfx_Buffer_initialize(se::State &s) { if (initWithBufferViewInfo) { auto bufferViewInfo = (cc::gfx::BufferViewInfo *)(args[0].toObject()->getPrivateData()); - ok &= cobj->initialize(*bufferViewInfo); + cobj->initialize(*bufferViewInfo); } else { auto bufferInfo = (cc::gfx::BufferInfo *)(args[0].toObject()->getPrivateData()); - ok &= cobj->initialize(*bufferInfo); + cobj->initialize(*bufferInfo); } ok &= boolean_to_seval(ok, &s.rval()); @@ -267,10 +240,10 @@ static bool js_gfx_Texture_initialize(se::State &s) { if (initWithTextureViewInfo) { auto textureViewInfo = (cc::gfx::TextureViewInfo *)(args[0].toObject()->getPrivateData()); - ok &= cobj->initialize(*textureViewInfo); + cobj->initialize(*textureViewInfo); } else { auto textureInfo = (cc::gfx::TextureInfo *)(args[0].toObject()->getPrivateData()); - ok &= cobj->initialize(*textureInfo); + cobj->initialize(*textureInfo); } ok &= boolean_to_seval(ok, &s.rval()); @@ -512,20 +485,11 @@ bool register_all_gfx_manual(se::Object *obj) { } se::Object *ns = nsVal.toObject(); - // js_register_gfx_SubPass(ns); - -#ifdef CC_USE_VULKAN - register_all_vk(obj); -#endif -#ifdef CC_USE_GLES3 - register_all_gles3(obj); -#endif -#ifdef CC_USE_GLES2 - register_all_gles2(obj); -#endif -#ifdef CC_USE_METAL - register_all_mtl(obj); -#endif + { + se::Value jsret; + nativevalue_to_se(cc::gfx::Device::getInstance(), jsret, nullptr); + ns->setProperty("deviceInstance", jsret); + } return true; } diff --git a/native/cocos/bindings/manual/jsb_module_register.cpp b/native/cocos/bindings/manual/jsb_module_register.cpp index 5e67b8772b..068a1924f7 100644 --- a/native/cocos/bindings/manual/jsb_module_register.cpp +++ b/native/cocos/bindings/manual/jsb_module_register.cpp @@ -37,7 +37,6 @@ #include "cocos/bindings/manual/jsb_network_manual.h" #include "cocos/bindings/manual/jsb_conversions.h" #include "cocos/bindings/manual/jsb_gfx_manual.h" -#include "cocos/bindings/manual/jsb_gfx_agent.h" #include "cocos/bindings/manual/jsb_global.h" #include "cocos/bindings/manual/jsb_platform.h" #include "cocos/bindings/manual/jsb_xmlhttprequest.h" @@ -115,7 +114,6 @@ bool jsb_register_all_modules() { se->addRegisterCallback(register_platform_bindings); se->addRegisterCallback(register_all_gfx); se->addRegisterCallback(register_all_gfx_manual); - se->addRegisterCallback(register_all_gfx_agent); se->addRegisterCallback(register_all_network); se->addRegisterCallback(register_all_network_manual); diff --git a/native/cocos/platform/android/Application-android.cpp b/native/cocos/platform/android/Application-android.cpp index c5581ac407..c6dc110843 100644 --- a/native/cocos/platform/android/Application-android.cpp +++ b/native/cocos/platform/android/Application-android.cpp @@ -36,6 +36,9 @@ #include "platform/android/jni/JniHelper.h" #include "platform/android/jni/JniCocosActivity.h" +#include "renderer/GFXDeviceCreator.h" +#include "pipeline/Define.h" + #define LOG_APP_TAG "Application_android Debug" #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_APP_TAG, __VA_ARGS__) @@ -47,7 +50,10 @@ extern "C" size_t __ctype_get_mb_cur_max(void) { } #endif +namespace cc { + namespace { + bool setCanvasCallback(se::Object *global) { auto viewLogicalSize = cc::Application::getInstance()->getViewLogicalSize(); se::AutoHandleScope scope; @@ -59,11 +65,20 @@ bool setCanvasCallback(se::Object *global) { (uintptr_t)cc::cocosApp.window); se->evalString(commandBuf); + gfx::DeviceInfo deviceInfo; + deviceInfo.windowHandle = (uintptr_t)cc::cocosApp.window; + deviceInfo.width = viewLogicalSize.x; + deviceInfo.height = viewLogicalSize.y; + deviceInfo.nativeWidth = viewLogicalSize.x; + deviceInfo.nativeHeight = viewLogicalSize.y; + deviceInfo.bindingMappingInfo = pipeline::bindingMappingInfo; + + gfx::DeviceCreator::createDevice(deviceInfo); + return true; } -} // namespace -namespace cc { +} // namespace Application *Application::_instance = nullptr; std::shared_ptr Application::_scheduler = nullptr; diff --git a/native/cocos/platform/ios/Application-ios.mm b/native/cocos/platform/ios/Application-ios.mm index 3e071b4cdc..d66d1eab62 100644 --- a/native/cocos/platform/ios/Application-ios.mm +++ b/native/cocos/platform/ios/Application-ios.mm @@ -34,6 +34,9 @@ #include "audio/include/AudioEngine.h" #include "platform/Device.h" +#include "renderer/GFXDeviceCreator.h" +#include "pipeline/Define.h" + @interface MyTimer : NSObject { cc::Application *_app; CADisplayLink *_displayLink; @@ -85,27 +88,39 @@ namespace cc { namespace { bool setCanvasCallback(se::Object* global) { auto viewLogicalSize = cc::Application::getInstance()->getViewLogicalSize(); - + CGRect nativeBounds = [[UIScreen mainScreen] nativeBounds]; int nativeWidth = static_cast(nativeBounds.size.width); int nativeHeight = static_cast(nativeBounds.size.height); auto orientation = cc::Device::getDeviceOrientation(); bool isLandscape = (orientation == cc::Device::Orientation::LANDSCAPE_RIGHT || orientation == cc::Device::Orientation::LANDSCAPE_LEFT); if (isLandscape) std::swap(nativeWidth, nativeHeight); - + char commandBuf[200] = {0}; // https://stackoverflow.com/questions/5795978/string-format-for-intptr-t-and-uintptr-t/41897226#41897226 // format intptr_t //set window.innerWidth/innerHeight in css pixel units + uintptr_t windowHandle = reinterpret_cast(UIApplication.sharedApplication.delegate.window.rootViewController.view); sprintf(commandBuf, "window.innerWidth = %d; window.innerHeight = %d; window.nativeWidth = %d; window.nativeHeight = %d; window.windowHandler = 0x%" PRIxPTR ";", static_cast(viewLogicalSize.x), static_cast(viewLogicalSize.y), nativeWidth, nativeHeight, - reinterpret_cast(UIApplication.sharedApplication.delegate.window.rootViewController.view)); - + windowHandle); + se::ScriptEngine* se = se::ScriptEngine::getInstance(); se->evalString(commandBuf); + + gfx::DeviceInfo deviceInfo; + deviceInfo.windowHandle = windowHandle; + deviceInfo.width = viewLogicalSize.x; + deviceInfo.height = viewLogicalSize.y; + deviceInfo.nativeWidth = nativeWidth; + deviceInfo.nativeHeight = nativeHeight; + deviceInfo.bindingMappingInfo = pipeline::bindingMappingInfo; + + gfx::DeviceCreator::createDevice(deviceInfo); + return true; } diff --git a/native/cocos/platform/mac/Application-mac.mm b/native/cocos/platform/mac/Application-mac.mm index df60d35b51..0557735f6e 100644 --- a/native/cocos/platform/mac/Application-mac.mm +++ b/native/cocos/platform/mac/Application-mac.mm @@ -32,6 +32,9 @@ #include #include +#include "renderer/GFXDeviceCreator.h" +#include "pipeline/Define.h" + #import @interface MyTimer : NSObject { @@ -99,6 +102,17 @@ bool setCanvasCallback(se::Object *global) { (int)(viewLogicalSize.y), (uintptr_t)view); se->evalString(commandBuf); + + gfx::DeviceInfo deviceInfo; + deviceInfo.windowHandle = (uintptr_t)view; + deviceInfo.width = viewLogicalSize.x; + deviceInfo.height = viewLogicalSize.y; + deviceInfo.nativeWidth = viewLogicalSize.x; + deviceInfo.nativeHeight = viewLogicalSize.y; + deviceInfo.bindingMappingInfo = pipeline::bindingMappingInfo; + + gfx::DeviceCreator::createDevice(deviceInfo); + return true; } diff --git a/native/cocos/platform/win32/Application-win32.cpp b/native/cocos/platform/win32/Application-win32.cpp index d3df74cbb8..2bd0ac2a94 100644 --- a/native/cocos/platform/win32/Application-win32.cpp +++ b/native/cocos/platform/win32/Application-win32.cpp @@ -27,30 +27,31 @@ #include "platform/Application.h" #include "platform/StdC.h" // need it to include Windows.h -#include -#include -#include -#include -#include -#include + +#include "audio/include/AudioEngine.h" +#include "base/AutoreleasePool.h" +#include "base/Scheduler.h" +#include "cocos/bindings/event/EventDispatcher.h" +#include "cocos/bindings/jswrapper/SeApi.h" #include "platform/FileUtils.h" #include "platform/win32/View-win32.h" -#include "cocos/bindings/jswrapper/SeApi.h" -#include "cocos/bindings/event/EventDispatcher.h" -#include "base/Scheduler.h" -#include "base/AutoreleasePool.h" -#include "audio/include/AudioEngine.h" +#include +#include +#include +#include +#include +#include extern std::shared_ptr cc_get_application_view(); namespace cc { -Application *Application::_instance = nullptr; +Application * Application::_instance = nullptr; std::shared_ptr Application::_scheduler = nullptr; Application::Application(int width, int height) { Application::_instance = this; - _scheduler = std::make_shared(); + _scheduler = std::make_shared(); FileUtils::getInstance()->addSearchPath("Resources", true); @@ -84,14 +85,14 @@ void Application::setPreferredFramesPerSecond(int fps) { if (fps == 0) return; - _fps = fps; + _fps = fps; _prefererredNanosecondsPerFrame = (long)(1.0 / _fps * NANOSECONDS_PER_SECOND); } Application::LanguageType Application::getCurrentLanguage() const { LanguageType ret = LanguageType::ENGLISH; - LCID localeID = GetUserDefaultLCID(); + LCID localeID = GetUserDefaultLCID(); unsigned short primaryLanguageID = localeID & 0xFF; switch (primaryLanguageID) { @@ -158,9 +159,9 @@ Application::LanguageType Application::getCurrentLanguage() const { } std::string Application::getCurrentLanguageCode() const { - LANGID lid = GetUserDefaultUILanguage(); + LANGID lid = GetUserDefaultUILanguage(); const LCID locale_id = MAKELCID(lid, SORT_DEFAULT); - int length = GetLocaleInfoA(locale_id, LOCALE_SISO639LANGNAME, nullptr, 0); + int length = GetLocaleInfoA(locale_id, LOCALE_SISO639LANGNAME, nullptr, 0); char *tempCode = new char[length]; GetLocaleInfoA(locale_id, LOCALE_SISO639LANGNAME, tempCode, length); @@ -172,15 +173,15 @@ std::string Application::getCurrentLanguageCode() const { bool Application::isDisplayStats() { se::AutoHandleScope hs; - se::Value ret; - char commandBuf[100] = "cc.profiler.isShowingStats();"; + se::Value ret; + char commandBuf[100] = "cc.profiler.isShowingStats();"; se::ScriptEngine::getInstance()->evalString(commandBuf, 100, &ret); return ret.toBoolean(); } void Application::setDisplayStats(bool isShow) { se::AutoHandleScope hs; - char commandBuf[100] = {0}; + char commandBuf[100] = {0}; sprintf(commandBuf, isShow ? "cc.profiler.showStats();" : "cc.profiler.hideStats();"); se::ScriptEngine::getInstance()->evalString(commandBuf); } @@ -194,9 +195,9 @@ Application::Platform Application::getPlatform() const { } bool Application::openURL(const std::string &url) { - WCHAR *temp = new WCHAR[url.size() + 1]; - int wchars_num = MultiByteToWideChar(CP_UTF8, 0, url.c_str(), url.size() + 1, temp, url.size() + 1); - HINSTANCE r = ShellExecuteW(NULL, L"open", temp, NULL, NULL, SW_SHOWNORMAL); + WCHAR * temp = new WCHAR[url.size() + 1]; + int wchars_num = MultiByteToWideChar(CP_UTF8, 0, url.c_str(), url.size() + 1, temp, url.size() + 1); + HINSTANCE r = ShellExecuteW(NULL, L"open", temp, NULL, NULL, SW_SHOWNORMAL); delete[] temp; return (size_t)r > 32; } diff --git a/native/cocos/platform/win32/View-win32.cpp b/native/cocos/platform/win32/View-win32.cpp index d3c2d1cafa..1209c7db80 100644 --- a/native/cocos/platform/win32/View-win32.cpp +++ b/native/cocos/platform/win32/View-win32.cpp @@ -27,6 +27,9 @@ #include "base/Log.h" #include +#include "renderer/GFXDeviceCreator.h" +#include "pipeline/Define.h" + using namespace cc; namespace { @@ -86,14 +89,25 @@ bool View::init() { CC_LOG_ERROR("Window could not be created! SDL_Error: %s\n", SDL_GetError()); return false; } + + gfx::DeviceInfo deviceInfo; + deviceInfo.windowHandle = (uintptr_t)getWindowHandler(); + deviceInfo.width = _width; + deviceInfo.height = _height; + deviceInfo.nativeWidth = _width; + deviceInfo.nativeHeight = _height; + deviceInfo.bindingMappingInfo = pipeline::bindingMappingInfo; + + gfx::DeviceCreator::createDevice(deviceInfo); + return true; } bool View::pollEvent(bool *quit, bool *resume, bool *pause) { int cnt = SDL_PollEvent(&sdlEvent); if (cnt == 0) return false; - cc::TouchEvent touch; - cc::MouseEvent mouse; + cc::TouchEvent touch; + cc::MouseEvent mouse; cc::KeyboardEvent keyboard; switch (sdlEvent.type) { case SDL_QUIT: { @@ -123,81 +137,81 @@ bool View::pollEvent(bool *quit, bool *resume, bool *pause) { } case SDL_MOUSEBUTTONDOWN: { SDL_MouseButtonEvent &event = sdlEvent.button; - mouse.type = MouseEvent::Type::DOWN; - mouse.x = static_cast(event.x); - mouse.y = static_cast(event.y); - mouse.button = event.button - 1; + mouse.type = MouseEvent::Type::DOWN; + mouse.x = static_cast(event.x); + mouse.y = static_cast(event.y); + mouse.button = event.button - 1; cc::EventDispatcher::dispatchMouseEvent(mouse); break; } case SDL_MOUSEBUTTONUP: { SDL_MouseButtonEvent &event = sdlEvent.button; - mouse.type = MouseEvent::Type::UP; - mouse.x = static_cast(event.x); - mouse.y = static_cast(event.y); - mouse.button = event.button - 1; + mouse.type = MouseEvent::Type::UP; + mouse.x = static_cast(event.x); + mouse.y = static_cast(event.y); + mouse.button = event.button - 1; cc::EventDispatcher::dispatchMouseEvent(mouse); break; } case SDL_MOUSEMOTION: { SDL_MouseMotionEvent &event = sdlEvent.motion; - mouse.type = MouseEvent::Type::MOVE; - mouse.x = static_cast(event.x); - mouse.y = static_cast(event.y); - mouse.button = 0; + mouse.type = MouseEvent::Type::MOVE; + mouse.x = static_cast(event.x); + mouse.y = static_cast(event.y); + mouse.button = 0; cc::EventDispatcher::dispatchMouseEvent(mouse); break; } case SDL_MOUSEWHEEL: { SDL_MouseWheelEvent &event = sdlEvent.wheel; - mouse.type = MouseEvent::Type::WHEEL; - mouse.x = static_cast(event.x); - mouse.y = static_cast(event.y); - mouse.button = 0; //TODO: direction + mouse.type = MouseEvent::Type::WHEEL; + mouse.x = static_cast(event.x); + mouse.y = static_cast(event.y); + mouse.button = 0; //TODO: direction cc::EventDispatcher::dispatchMouseEvent(mouse); break; } case SDL_FINGERUP: { SDL_TouchFingerEvent &event = sdlEvent.tfinger; - touch.type = TouchEvent::Type::ENDED; - touch.touches = {TouchInfo(event.x, event.y, (int)event.fingerId)}; + touch.type = TouchEvent::Type::ENDED; + touch.touches = {TouchInfo(event.x, event.y, (int)event.fingerId)}; cc::EventDispatcher::dispatchTouchEvent(touch); break; } case SDL_FINGERDOWN: { SDL_TouchFingerEvent &event = sdlEvent.tfinger; - touch.type = TouchEvent::Type::BEGAN; - touch.touches = {TouchInfo(event.x, event.y, (int)event.fingerId)}; + touch.type = TouchEvent::Type::BEGAN; + touch.touches = {TouchInfo(event.x, event.y, (int)event.fingerId)}; cc::EventDispatcher::dispatchTouchEvent(touch); break; } case SDL_FINGERMOTION: { SDL_TouchFingerEvent &event = sdlEvent.tfinger; - touch.type = TouchEvent::Type::MOVED; - touch.touches = {TouchInfo(event.x, event.y, (int)event.fingerId)}; + touch.type = TouchEvent::Type::MOVED; + touch.touches = {TouchInfo(event.x, event.y, (int)event.fingerId)}; cc::EventDispatcher::dispatchTouchEvent(touch); break; } case SDL_KEYDOWN: { SDL_KeyboardEvent &event = sdlEvent.key; - auto mode = event.keysym.mod; - keyboard.action = KeyboardEvent::Action::PRESS; - keyboard.key = sdl_keycode_to_cocos_code(event.keysym.sym, mode); - keyboard.altKeyActive = mode & KMOD_ALT; - keyboard.ctrlKeyActive = mode & KMOD_CTRL; - keyboard.shiftKeyActive = mode & KMOD_SHIFT; + auto mode = event.keysym.mod; + keyboard.action = KeyboardEvent::Action::PRESS; + keyboard.key = sdl_keycode_to_cocos_code(event.keysym.sym, mode); + keyboard.altKeyActive = mode & KMOD_ALT; + keyboard.ctrlKeyActive = mode & KMOD_CTRL; + keyboard.shiftKeyActive = mode & KMOD_SHIFT; //CC_LOG_DEBUG("==> key %d -> code %d", event.keysym.sym, keyboard.key); cc::EventDispatcher::dispatchKeyboardEvent(keyboard); break; } case SDL_KEYUP: { SDL_KeyboardEvent &event = sdlEvent.key; - auto mode = event.keysym.mod; - keyboard.action = KeyboardEvent::Action::RELEASE; - keyboard.key = sdl_keycode_to_cocos_code(event.keysym.sym, mode); - keyboard.altKeyActive = mode & KMOD_ALT; - keyboard.ctrlKeyActive = mode & KMOD_CTRL; - keyboard.shiftKeyActive = mode & KMOD_SHIFT; + auto mode = event.keysym.mod; + keyboard.action = KeyboardEvent::Action::RELEASE; + keyboard.key = sdl_keycode_to_cocos_code(event.keysym.sym, mode); + keyboard.altKeyActive = mode & KMOD_ALT; + keyboard.ctrlKeyActive = mode & KMOD_CTRL; + keyboard.shiftKeyActive = mode & KMOD_SHIFT; cc::EventDispatcher::dispatchKeyboardEvent(keyboard); break; } diff --git a/native/cocos/renderer/GFXDeviceCreator.h b/native/cocos/renderer/GFXDeviceCreator.h new file mode 100644 index 0000000000..7a043eb560 --- /dev/null +++ b/native/cocos/renderer/GFXDeviceCreator.h @@ -0,0 +1,106 @@ +/**************************************************************************** + Copyright (c) 2019-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 "bindings/event/CustomEventTypes.h" +#include "bindings/event/EventDispatcher.h" +#include "gfx-agent/DeviceAgent.h" +#include "gfx-empty/EmptyDevice.h" + +#ifdef CC_USE_VULKAN + #include "gfx-vulkan/GFXVulkan.h" +#endif + +#ifdef CC_USE_METAL + #include "gfx-metal/GFXMTL.h" +#endif + +#ifdef CC_USE_GLES3 + #include "gfx-gles3/GFXGLES3.h" +#endif + +#ifdef CC_USE_GLES2 + #include "gfx-gles2/GFXGLES2.h" +#endif + +namespace cc { +namespace gfx { + +class CC_DLL DeviceCreator final { +public: + static Device *createDevice(const DeviceInfo &info) { + Device *device = nullptr; + +#ifdef CC_USE_VULKAN + if (tryCreate(info, device)) return device; +#endif + +#ifdef CC_USE_METAL + if (tryCreate(info, device)) return device; +#endif + +#ifdef CC_USE_GLES3 + if (tryCreate(info, device)) return device; +#endif + +#ifdef CC_USE_GLES2 + if (tryCreate(info, device)) return device; +#endif + + if (tryCreate(info, device)) return device; + + return nullptr; + } + +private: + template ::value>> + static bool tryCreate(const DeviceInfo &info, Device *&device) { + device = CC_NEW(DeviceCtor); + + device = CC_NEW(gfx::DeviceAgent(device)); + + if (!device->initialize(info)) { + CC_SAFE_DELETE(device); + return false; + } + + EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [device](const CustomEvent &e) -> void { + DeviceCreator::releaseSurface(device, reinterpret_cast(e.args->ptrVal)); + }); + + EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [device](const CustomEvent &e) -> void { + DeviceCreator::acquireSurface(device, reinterpret_cast(e.args->ptrVal)); + }); + + return true; + } + + static void releaseSurface(Device *device, uintptr_t windowHandle) { device->releaseSurface(windowHandle); } + static void acquireSurface(Device *device, uintptr_t windowHandle) { device->acquireSurface(windowHandle); } +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/frame-graph/Resource.h b/native/cocos/renderer/frame-graph/Resource.h index f4d85e565e..f0ee2ea46e 100644 --- a/native/cocos/renderer/frame-graph/Resource.h +++ b/native/cocos/renderer/frame-graph/Resource.h @@ -64,7 +64,7 @@ public: using Descriptor = DescriptorType; using DescriptorHasher = DescriptorHasherType; - Resource() noexcept = default; + Resource() = default; explicit Resource(const Descriptor &desc) noexcept; ~Resource() = default; Resource(const Resource &) = default; diff --git a/native/cocos/renderer/gfx-agent/GFXBufferAgent.cpp b/native/cocos/renderer/gfx-agent/BufferAgent.cpp similarity index 67% rename from native/cocos/renderer/gfx-agent/GFXBufferAgent.cpp rename to native/cocos/renderer/gfx-agent/BufferAgent.cpp index 60c7a54f69..62818dfeac 100644 --- a/native/cocos/renderer/gfx-agent/GFXBufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/BufferAgent.cpp @@ -26,69 +26,62 @@ #include "base/CoreStd.h" #include "base/threading/MessageQueue.h" -#include "GFXBufferAgent.h" -#include "GFXDeviceAgent.h" -#include "GFXLinearAllocatorPool.h" +#include "BufferAgent.h" +#include "DeviceAgent.h" +#include "LinearAllocatorPool.h" namespace cc { namespace gfx { BufferAgent::~BufferAgent() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), BufferDestruct, actor, _actor, { - CC_DELETE(actor); + CC_SAFE_DELETE(actor); }); } -bool BufferAgent::initialize(const BufferInfo &info) { - _usage = info.usage; - _memUsage = info.memUsage; - _size = info.size; - _flags = info.flags; - _stride = std::max(info.stride, 1u); - _count = _size / _stride; - +void BufferAgent::doInit(const BufferInfo &info) { ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), BufferInit, actor, getActor(), info, info, { actor->initialize(info); }); - - return true; } -bool BufferAgent::initialize(const BufferViewInfo &info) { - _usage = info.buffer->getUsage(); - _memUsage = info.buffer->getMemUsage(); - _flags = info.buffer->getFlags(); - _offset = info.offset; - _size = _stride = info.range; - _count = 1u; - +void BufferAgent::doInit(const BufferViewInfo &info) { BufferViewInfo actorInfo = info; - actorInfo.buffer = ((BufferAgent *)info.buffer)->getActor(); + actorInfo.buffer = ((BufferAgent *)info.buffer)->getActor(); ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), BufferViewInit, actor, getActor(), info, actorInfo, { actor->initialize(info); }); - - return true; } -void BufferAgent::destroy() { +void BufferAgent::doResize(uint size) { + ENQUEUE_MESSAGE_2( + DeviceAgent::getInstance()->getMessageQueue(), + BufferResize, + actor, getActor(), + size, size, + { + actor->resize(size); + }); +} + +void BufferAgent::doDestroy() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), BufferDestroy, actor, getActor(), { @@ -97,11 +90,11 @@ void BufferAgent::destroy() { } void BufferAgent::update(void *buffer, uint size) { - uint8_t *actorBuffer = ((DeviceAgent *)_device)->getMainAllocator()->allocate(size); + uint8_t *actorBuffer = DeviceAgent::getInstance()->getMainAllocator()->allocate(size); memcpy(actorBuffer, buffer, size); ENQUEUE_MESSAGE_3( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), BufferUpdate, actor, getActor(), buffer, actorBuffer, @@ -111,19 +104,5 @@ void BufferAgent::update(void *buffer, uint size) { }); } -void BufferAgent::resize(uint size) { - _size = size; - _count = size / _stride; - - ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), - BufferResize, - actor, getActor(), - size, size, - { - actor->resize(size); - }); -} - } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-agent/GFXBufferAgent.h b/native/cocos/renderer/gfx-agent/BufferAgent.h similarity index 87% rename from native/cocos/renderer/gfx-agent/GFXBufferAgent.h rename to native/cocos/renderer/gfx-agent/BufferAgent.h index d20071be72..b0286d1ba3 100644 --- a/native/cocos/renderer/gfx-agent/GFXBufferAgent.h +++ b/native/cocos/renderer/gfx-agent/BufferAgent.h @@ -25,7 +25,7 @@ #pragma once -#include "GFXAgent.h" +#include "base/Agent.h" #include "gfx-base/GFXBuffer.h" namespace cc { @@ -34,14 +34,15 @@ namespace gfx { class CC_DLL BufferAgent final : public Agent { public: using Agent::Agent; - BufferAgent(Device *device) = delete; ~BufferAgent() override; - bool initialize(const BufferInfo &info) override; - bool initialize(const BufferViewInfo &info) override; - void destroy() override; - void resize(uint size) override; void update(void *buffer, uint size) override; + +protected: + void doInit(const BufferInfo &info) override; + void doInit(const BufferViewInfo &info) override; + void doResize(uint size) override; + void doDestroy() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/GFXCommandBufferAgent.cpp b/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp similarity index 93% rename from native/cocos/renderer/gfx-agent/GFXCommandBufferAgent.cpp rename to native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp index bbb63e5e28..fc1e6ee7ee 100644 --- a/native/cocos/renderer/gfx-agent/GFXCommandBufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/CommandBufferAgent.cpp @@ -27,17 +27,17 @@ #include "base/threading/MessageQueue.h" #include "base/job-system/JobSystem.h" -#include "GFXBufferAgent.h" -#include "GFXCommandBufferAgent.h" -#include "GFXDescriptorSetAgent.h" -#include "GFXDeviceAgent.h" -#include "GFXFramebufferAgent.h" -#include "GFXInputAssemblerAgent.h" -#include "GFXLinearAllocatorPool.h" -#include "GFXPipelineStateAgent.h" -#include "GFXQueueAgent.h" -#include "GFXRenderPassAgent.h" -#include "GFXTextureAgent.h" +#include "BufferAgent.h" +#include "CommandBufferAgent.h" +#include "DescriptorSetAgent.h" +#include "DeviceAgent.h" +#include "FramebufferAgent.h" +#include "InputAssemblerAgent.h" +#include "LinearAllocatorPool.h" +#include "PipelineStateAgent.h" +#include "QueueAgent.h" +#include "RenderPassAgent.h" +#include "TextureAgent.h" namespace cc { namespace gfx { @@ -66,10 +66,10 @@ void CommandBufferAgent::flushCommands(uint count, CommandBufferAgent *const *cm CommandBufferAgent::~CommandBufferAgent() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), CommandBufferDestruct, + DeviceAgent::getInstance()->getMessageQueue(), CommandBufferDestruct, actor, _actor, { - CC_DELETE(actor); + CC_SAFE_DELETE(actor); }); } @@ -79,7 +79,7 @@ void CommandBufferAgent::initMessageQueue() { for (uint i = 0u; i < MAX_CPU_FRAME_AHEAD + 1; ++i) { _allocatorPools[i] = CC_NEW(LinearAllocatorPool); } - DeviceAgent *device = (DeviceAgent *)_device; + DeviceAgent *device = DeviceAgent::getInstance(); device->_cmdBuffRefs.insert(this); _messageQueue = CC_NEW(MessageQueue); @@ -87,10 +87,10 @@ void CommandBufferAgent::initMessageQueue() { } void CommandBufferAgent::destroyMessageQueue() { - ((DeviceAgent *)_device)->getMessageQueue()->kickAndWait(); + DeviceAgent::getInstance()->getMessageQueue()->kickAndWait(); CC_SAFE_DELETE(_messageQueue); - ((DeviceAgent *)_device)->_cmdBuffRefs.erase(this); + DeviceAgent::getInstance()->_cmdBuffRefs.erase(this); for (LinearAllocatorPool *pool : _allocatorPools) { CC_SAFE_DELETE(pool); } @@ -98,34 +98,29 @@ void CommandBufferAgent::destroyMessageQueue() { } LinearAllocatorPool *CommandBufferAgent::getAllocator() { - return _allocatorPools[((DeviceAgent *)_device)->_currentIndex]; + return _allocatorPools[DeviceAgent::getInstance()->_currentIndex]; } -bool CommandBufferAgent::initialize(const CommandBufferInfo &info) { - _type = info.type; - _queue = info.queue; - +void CommandBufferAgent::doInit(const CommandBufferInfo &info) { initMessageQueue(); CommandBufferInfo actorInfo = info; actorInfo.queue = ((QueueAgent *)info.queue)->getActor(); ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), CommandBufferInit, + DeviceAgent::getInstance()->getMessageQueue(), CommandBufferInit, actor, getActor(), info, actorInfo, { actor->initialize(info); }); - - return true; } -void CommandBufferAgent::destroy() { +void CommandBufferAgent::doDestroy() { destroyMessageQueue(); ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), CommandBufferDestroy, + DeviceAgent::getInstance()->getMessageQueue(), CommandBufferDestroy, actor, getActor(), { actor->destroy(); diff --git a/native/cocos/renderer/gfx-agent/GFXCommandBufferAgent.h b/native/cocos/renderer/gfx-agent/CommandBufferAgent.h similarity index 96% rename from native/cocos/renderer/gfx-agent/GFXCommandBufferAgent.h rename to native/cocos/renderer/gfx-agent/CommandBufferAgent.h index 2b993839fd..1613a14c6e 100644 --- a/native/cocos/renderer/gfx-agent/GFXCommandBufferAgent.h +++ b/native/cocos/renderer/gfx-agent/CommandBufferAgent.h @@ -25,7 +25,7 @@ #pragma once -#include "GFXAgent.h" +#include "base/Agent.h" #include "gfx-base/GFXCommandBuffer.h" namespace cc { @@ -39,13 +39,10 @@ class LinearAllocatorPool; class CC_DLL CommandBufferAgent final : public Agent { public: using Agent::Agent; - CommandBufferAgent(Device *device) = delete; ~CommandBufferAgent() override; static void flushCommands(uint count, CommandBufferAgent *const *cmdBuffs, bool multiThreaded); - bool initialize(const CommandBufferInfo &info) override; - void destroy() override; void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; void end() override; void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; @@ -76,9 +73,12 @@ public: CC_INLINE MessageQueue *getMessageQueue() { return _messageQueue; } LinearAllocatorPool *getAllocator(); -private: +protected: friend class DeviceAgent; + void doInit(const CommandBufferInfo &info) override; + void doDestroy() override; + void initMessageQueue(); void destroyMessageQueue(); MessageQueue *_messageQueue = nullptr; diff --git a/native/cocos/renderer/gfx-agent/GFXDescriptorSetAgent.cpp b/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp similarity index 76% rename from native/cocos/renderer/gfx-agent/GFXDescriptorSetAgent.cpp rename to native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp index 7b9b6ad132..3918326ada 100644 --- a/native/cocos/renderer/gfx-agent/GFXDescriptorSetAgent.cpp +++ b/native/cocos/renderer/gfx-agent/DescriptorSetAgent.cpp @@ -26,56 +26,43 @@ #include "base/CoreStd.h" #include "base/threading/MessageQueue.h" -#include "GFXBufferAgent.h" -#include "GFXDescriptorSetAgent.h" -#include "GFXDescriptorSetLayoutAgent.h" -#include "GFXDeviceAgent.h" -#include "GFXSamplerAgent.h" -#include "GFXTextureAgent.h" +#include "BufferAgent.h" +#include "DescriptorSetAgent.h" +#include "DescriptorSetLayoutAgent.h" +#include "DeviceAgent.h" +#include "SamplerAgent.h" +#include "TextureAgent.h" namespace cc { namespace gfx { DescriptorSetAgent::~DescriptorSetAgent() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), DescriptorSetDestruct, actor, _actor, { - CC_DELETE(actor); + CC_SAFE_DELETE(actor); }); } -bool DescriptorSetAgent::initialize(const DescriptorSetInfo &info) { - _layout = info.layout; - uint descriptorCount = _layout->getDescriptorCount(); - _buffers.resize(descriptorCount); - _textures.resize(descriptorCount); - _samplers.resize(descriptorCount); - +void DescriptorSetAgent::doInit(const DescriptorSetInfo &info) { DescriptorSetInfo actorInfo; actorInfo.layout = ((DescriptorSetLayoutAgent *)info.layout)->getActor(); ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), DescriptorSetInit, actor, getActor(), info, actorInfo, { actor->initialize(info); }); - - return true; } -void DescriptorSetAgent::destroy() { - // do remember to clear these or else it might not be properly updated when reused - _buffers.clear(); - _textures.clear(); - _samplers.clear(); - +void DescriptorSetAgent::doDestroy() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), DescriptorSetDestroy, actor, getActor(), { @@ -85,7 +72,7 @@ void DescriptorSetAgent::destroy() { void DescriptorSetAgent::update() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), DescriptorSetUpdate, actor, getActor(), { @@ -97,7 +84,7 @@ void DescriptorSetAgent::bindBuffer(uint binding, Buffer *buffer, uint index) { DescriptorSet::bindBuffer(binding, buffer, index); ENQUEUE_MESSAGE_4( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), DescriptorSetBindBuffer, actor, getActor(), binding, binding, @@ -112,7 +99,7 @@ void DescriptorSetAgent::bindTexture(uint binding, Texture *texture, uint index) DescriptorSet::bindTexture(binding, texture, index); ENQUEUE_MESSAGE_4( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), DescriptorSetBindTexture, actor, getActor(), binding, binding, @@ -127,7 +114,7 @@ void DescriptorSetAgent::bindSampler(uint binding, Sampler *sampler, uint index) DescriptorSet::bindSampler(binding, sampler, index); ENQUEUE_MESSAGE_4( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), DescriptorSetBindSampler, actor, getActor(), binding, binding, diff --git a/native/cocos/renderer/gfx-agent/GFXDescriptorSetAgent.h b/native/cocos/renderer/gfx-agent/DescriptorSetAgent.h similarity index 92% rename from native/cocos/renderer/gfx-agent/GFXDescriptorSetAgent.h rename to native/cocos/renderer/gfx-agent/DescriptorSetAgent.h index 3fd75cc7c2..35e89019db 100644 --- a/native/cocos/renderer/gfx-agent/GFXDescriptorSetAgent.h +++ b/native/cocos/renderer/gfx-agent/DescriptorSetAgent.h @@ -25,7 +25,7 @@ #pragma once -#include "GFXAgent.h" +#include "base/Agent.h" #include "gfx-base/GFXDescriptorSet.h" namespace cc { @@ -34,16 +34,17 @@ namespace gfx { class CC_DLL DescriptorSetAgent final : public Agent { public: using Agent::Agent; - DescriptorSetAgent(Device *device) = delete; ~DescriptorSetAgent() override; - bool initialize(const DescriptorSetInfo &info) override; - void destroy() override; 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; + +protected: + void doInit(const DescriptorSetInfo &info) override; + void doDestroy() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/DescriptorSetLayoutAgent.cpp b/native/cocos/renderer/gfx-agent/DescriptorSetLayoutAgent.cpp new file mode 100644 index 0000000000..4811a5bc8e --- /dev/null +++ b/native/cocos/renderer/gfx-agent/DescriptorSetLayoutAgent.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "base/CoreStd.h" +#include "base/threading/MessageQueue.h" + +#include "DeviceAgent.h" +#include "DescriptorSetLayoutAgent.h" + +namespace cc { +namespace gfx { + +DescriptorSetLayoutAgent::~DescriptorSetLayoutAgent() { + ENQUEUE_MESSAGE_1( + DeviceAgent::getInstance()->getMessageQueue(), + DescriptorSetLayoutDestruct, + actor, _actor, + { + CC_SAFE_DELETE(actor); + }); +} + +void DescriptorSetLayoutAgent::doInit(const DescriptorSetLayoutInfo &info) { + ENQUEUE_MESSAGE_2( + DeviceAgent::getInstance()->getMessageQueue(), + DescriptorSetLayoutInit, + actor, getActor(), + info, info, + { + actor->initialize(info); + }); +} + +void DescriptorSetLayoutAgent::doDestroy() { + ENQUEUE_MESSAGE_1( + DeviceAgent::getInstance()->getMessageQueue(), + DescriptorSetLayoutDestroy, + actor, getActor(), + { + actor->destroy(); + }); +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-agent/GFXDescriptorSetLayoutAgent.h b/native/cocos/renderer/gfx-agent/DescriptorSetLayoutAgent.h similarity index 90% rename from native/cocos/renderer/gfx-agent/GFXDescriptorSetLayoutAgent.h rename to native/cocos/renderer/gfx-agent/DescriptorSetLayoutAgent.h index bfc9cbdc0c..417b585df0 100644 --- a/native/cocos/renderer/gfx-agent/GFXDescriptorSetLayoutAgent.h +++ b/native/cocos/renderer/gfx-agent/DescriptorSetLayoutAgent.h @@ -25,7 +25,7 @@ #pragma once -#include "GFXAgent.h" +#include "base/Agent.h" #include "gfx-base/GFXDescriptorSetLayout.h" namespace cc { @@ -34,11 +34,11 @@ namespace gfx { class CC_DLL DescriptorSetLayoutAgent final : public Agent { public: using Agent::Agent; - DescriptorSetLayoutAgent(Device *device) = delete; ~DescriptorSetLayoutAgent() override; - bool initialize(const DescriptorSetLayoutInfo &info) override; - void destroy() override; +protected: + void doInit(const DescriptorSetLayoutInfo &info) override; + void doDestroy() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/GFXDeviceAgent.cpp b/native/cocos/renderer/gfx-agent/DeviceAgent.cpp similarity index 72% rename from native/cocos/renderer/gfx-agent/GFXDeviceAgent.cpp rename to native/cocos/renderer/gfx-agent/DeviceAgent.cpp index 7e13e1d71b..647201f583 100644 --- a/native/cocos/renderer/gfx-agent/GFXDeviceAgent.cpp +++ b/native/cocos/renderer/gfx-agent/DeviceAgent.cpp @@ -26,44 +26,41 @@ #include "base/CoreStd.h" #include "base/threading/MessageQueue.h" -#include "GFXBufferAgent.h" -#include "GFXCommandBufferAgent.h" -#include "GFXDescriptorSetAgent.h" -#include "GFXDescriptorSetLayoutAgent.h" -#include "GFXDeviceAgent.h" -#include "GFXFramebufferAgent.h" -#include "GFXInputAssemblerAgent.h" -#include "GFXLinearAllocatorPool.h" -#include "GFXPipelineLayoutAgent.h" -#include "GFXPipelineStateAgent.h" -#include "GFXQueueAgent.h" -#include "GFXRenderPassAgent.h" -#include "GFXSamplerAgent.h" -#include "GFXShaderAgent.h" -#include "GFXTextureAgent.h" +#include "BufferAgent.h" +#include "CommandBufferAgent.h" +#include "DescriptorSetAgent.h" +#include "DescriptorSetLayoutAgent.h" +#include "DeviceAgent.h" +#include "FramebufferAgent.h" +#include "InputAssemblerAgent.h" +#include "LinearAllocatorPool.h" +#include "PipelineLayoutAgent.h" +#include "PipelineStateAgent.h" +#include "QueueAgent.h" +#include "RenderPassAgent.h" +#include "SamplerAgent.h" +#include "ShaderAgent.h" +#include "TextureAgent.h" namespace cc { namespace gfx { -DeviceAgent::~DeviceAgent() { - CC_SAFE_DELETE(_actor); +DeviceAgent *DeviceAgent::_instance = nullptr; + +DeviceAgent *DeviceAgent::getInstance() { + return DeviceAgent::_instance; } -bool DeviceAgent::initialize(const DeviceInfo &info) { - _width = info.width; - _height = info.height; - _nativeWidth = info.nativeWidth; - _nativeHeight = info.nativeHeight; - _windowHandle = info.windowHandle; +DeviceAgent::DeviceAgent(Device *device) : Agent(device) { + DeviceAgent::_instance = this; +} - _bindingMappingInfo = info.bindingMappingInfo; - if (_bindingMappingInfo.bufferOffsets.empty()) { - _bindingMappingInfo.bufferOffsets.push_back(0); - } - if (_bindingMappingInfo.samplerOffsets.empty()) { - _bindingMappingInfo.samplerOffsets.push_back(0); - } +DeviceAgent::~DeviceAgent() { + CC_SAFE_DELETE(_actor); + DeviceAgent::_instance = nullptr; +} +bool DeviceAgent::doInit(const DeviceInfo &info) { if (!_actor->initialize(info)) { return false; } @@ -71,8 +68,8 @@ bool DeviceAgent::initialize(const DeviceInfo &info) { _context = _actor->getContext(); _API = _actor->getGfxAPI(); _deviceName = _actor->getDeviceName(); - _queue = CC_NEW(QueueAgent(_actor->getQueue(), this)); - _cmdBuff = CC_NEW(CommandBufferAgent(_actor->getCommandBuffer(), this)); + _queue = CC_NEW(QueueAgent(_actor->getQueue())); + _cmdBuff = CC_NEW(CommandBufferAgent(_actor->getCommandBuffer())); ((CommandBufferAgent *)_cmdBuff)->_queue = _queue; _renderer = _actor->getRenderer(); _vendor = _actor->getVendor(); @@ -92,7 +89,7 @@ bool DeviceAgent::initialize(const DeviceInfo &info) { return true; } -void DeviceAgent::destroy() { +void DeviceAgent::doDestroy() { ENQUEUE_MESSAGE_1( getMessageQueue(), DeviceDestroy, actor, getActor(), @@ -122,9 +119,6 @@ void DeviceAgent::destroy() { } void DeviceAgent::resize(uint width, uint height) { - _width = _nativeWidth = width; - _height = _nativeHeight = height; - ENQUEUE_MESSAGE_3( getMessageQueue(), DeviceResize, actor, getActor(), @@ -174,7 +168,7 @@ void DeviceAgent::setMultithreaded(bool multithreaded) { _actor->bindRenderContext(false); _mainEncoder->runConsumerThread(); ENQUEUE_MESSAGE_1( - _mainEncoder, DeviceMakeCurrent, + _mainEncoder, DeviceMakeCurrentTrue, actor, _actor, { actor->bindDeviceContext(true); @@ -185,7 +179,7 @@ void DeviceAgent::setMultithreaded(bool multithreaded) { } } else { ENQUEUE_MESSAGE_1( - _mainEncoder, DeviceMakeCurrent, + _mainEncoder, DeviceMakeCurrentFalse, actor, _actor, { actor->bindDeviceContext(false); @@ -200,81 +194,69 @@ void DeviceAgent::setMultithreaded(bool multithreaded) { } } -CommandBuffer *DeviceAgent::doCreateCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { - CommandBuffer *actor = _actor->doCreateCommandBuffer(info, true); - return CC_NEW(CommandBufferAgent(actor, this)); +CommandBuffer *DeviceAgent::createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { + CommandBuffer *actor = _actor->createCommandBuffer(info, true); + return CC_NEW(CommandBufferAgent(actor)); } Queue *DeviceAgent::createQueue() { - Queue * actor = _actor->createQueue(); - QueueAgent *agent = CC_NEW(QueueAgent(actor, this)); - return agent; + Queue *actor = _actor->createQueue(); + return CC_NEW(QueueAgent(actor)); } Buffer *DeviceAgent::createBuffer() { - Buffer * actor = _actor->createBuffer(); - BufferAgent *agent = CC_NEW(BufferAgent(actor, this)); - return agent; + Buffer *actor = _actor->createBuffer(); + return CC_NEW(BufferAgent(actor)); } Texture *DeviceAgent::createTexture() { - Texture * actor = _actor->createTexture(); - TextureAgent *agent = CC_NEW(TextureAgent(actor, this)); - return agent; + Texture *actor = _actor->createTexture(); + return CC_NEW(TextureAgent(actor)); } Sampler *DeviceAgent::createSampler() { - Sampler * actor = _actor->createSampler(); - SamplerAgent *agent = CC_NEW(SamplerAgent(actor, this)); - return agent; + Sampler *actor = _actor->createSampler(); + return CC_NEW(SamplerAgent(actor)); } Shader *DeviceAgent::createShader() { - Shader * actor = _actor->createShader(); - ShaderAgent *agent = CC_NEW(ShaderAgent(actor, this)); - return agent; + Shader *actor = _actor->createShader(); + return CC_NEW(ShaderAgent(actor)); } InputAssembler *DeviceAgent::createInputAssembler() { - InputAssembler * actor = _actor->createInputAssembler(); - InputAssemblerAgent *agent = CC_NEW(InputAssemblerAgent(actor, this)); - return agent; + InputAssembler *actor = _actor->createInputAssembler(); + return CC_NEW(InputAssemblerAgent(actor)); } RenderPass *DeviceAgent::createRenderPass() { - RenderPass * actor = _actor->createRenderPass(); - RenderPassAgent *agent = CC_NEW(RenderPassAgent(actor, this)); - return agent; + RenderPass *actor = _actor->createRenderPass(); + return CC_NEW(RenderPassAgent(actor)); } Framebuffer *DeviceAgent::createFramebuffer() { - Framebuffer * actor = _actor->createFramebuffer(); - FramebufferAgent *agent = CC_NEW(FramebufferAgent(actor, this)); - return agent; + Framebuffer *actor = _actor->createFramebuffer(); + return CC_NEW(FramebufferAgent(actor)); } DescriptorSet *DeviceAgent::createDescriptorSet() { - DescriptorSet * actor = _actor->createDescriptorSet(); - DescriptorSetAgent *agent = CC_NEW(DescriptorSetAgent(actor, this)); - return agent; + DescriptorSet *actor = _actor->createDescriptorSet(); + return CC_NEW(DescriptorSetAgent(actor)); } DescriptorSetLayout *DeviceAgent::createDescriptorSetLayout() { - DescriptorSetLayout * actor = _actor->createDescriptorSetLayout(); - DescriptorSetLayoutAgent *agent = CC_NEW(DescriptorSetLayoutAgent(actor, this)); - return agent; + DescriptorSetLayout *actor = _actor->createDescriptorSetLayout(); + return CC_NEW(DescriptorSetLayoutAgent(actor)); } PipelineLayout *DeviceAgent::createPipelineLayout() { - PipelineLayout * actor = _actor->createPipelineLayout(); - PipelineLayoutAgent *agent = CC_NEW(PipelineLayoutAgent(actor, this)); - return agent; + PipelineLayout *actor = _actor->createPipelineLayout(); + return CC_NEW(PipelineLayoutAgent(actor)); } PipelineState *DeviceAgent::createPipelineState() { - PipelineState * actor = _actor->createPipelineState(); - PipelineStateAgent *agent = CC_NEW(PipelineStateAgent(actor, this)); - return agent; + PipelineState *actor = _actor->createPipelineState(); + return CC_NEW(PipelineStateAgent(actor)); } GlobalBarrier *DeviceAgent::createGlobalBarrier() { diff --git a/native/cocos/renderer/gfx-agent/GFXDeviceAgent.h b/native/cocos/renderer/gfx-agent/DeviceAgent.h similarity index 81% rename from native/cocos/renderer/gfx-agent/GFXDeviceAgent.h rename to native/cocos/renderer/gfx-agent/DeviceAgent.h index a8d0936651..5c534641fa 100644 --- a/native/cocos/renderer/gfx-agent/GFXDeviceAgent.h +++ b/native/cocos/renderer/gfx-agent/DeviceAgent.h @@ -25,9 +25,9 @@ #pragma once -#include "gfx-base/GFXDevice.h" -#include "GFXAgent.h" +#include "base/Agent.h" #include "base/threading/Semaphore.h" +#include "gfx-base/GFXDevice.h" namespace cc { @@ -42,18 +42,32 @@ constexpr uint MAX_CPU_FRAME_AHEAD = 1u; class CC_DLL DeviceAgent final : public Agent { public: - using Agent::Agent; - DeviceAgent(Device *const actor) noexcept - : Agent(actor, nullptr) {} + static DeviceAgent *getInstance(); + ~DeviceAgent() override; - bool initialize(const DeviceInfo &info) override; - void destroy() override; + using Device::copyBuffersToTexture; + using Device::createBuffer; + using Device::createCommandBuffer; + using Device::createDescriptorSet; + using Device::createDescriptorSetLayout; + using Device::createFramebuffer; + using Device::createGlobalBarrier; + using Device::createInputAssembler; + using Device::createPipelineLayout; + using Device::createPipelineState; + using Device::createQueue; + using Device::createRenderPass; + using Device::createSampler; + using Device::createShader; + using Device::createTexture; + using Device::createTextureBarrier; + void resize(uint width, uint height) override; void acquire() override; void present() override; - CommandBuffer * doCreateCommandBuffer(const CommandBufferInfo &info, bool hasAgent) override; + CommandBuffer * createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) override; Queue * createQueue() override; Buffer * createBuffer() override; Texture * createTexture() override; @@ -86,8 +100,16 @@ public: LinearAllocatorPool *getMainAllocator() const { return _allocatorPools[_currentIndex]; } protected: + static DeviceAgent *_instance; + + friend class DeviceCreator; friend class CommandBufferAgent; + DeviceAgent(Device *device); + + bool doInit(const DeviceInfo &info) override; + void doDestroy() override; + bool _multithreaded{false}; MessageQueue *_mainEncoder{nullptr}; diff --git a/native/cocos/renderer/gfx-agent/GFXFramebufferAgent.cpp b/native/cocos/renderer/gfx-agent/FramebufferAgent.cpp similarity index 81% rename from native/cocos/renderer/gfx-agent/GFXFramebufferAgent.cpp rename to native/cocos/renderer/gfx-agent/FramebufferAgent.cpp index fbb1ac454a..240d40ccca 100644 --- a/native/cocos/renderer/gfx-agent/GFXFramebufferAgent.cpp +++ b/native/cocos/renderer/gfx-agent/FramebufferAgent.cpp @@ -26,29 +26,25 @@ #include "base/CoreStd.h" #include "base/threading/MessageQueue.h" -#include "GFXDeviceAgent.h" -#include "GFXFramebufferAgent.h" -#include "GFXRenderPassAgent.h" -#include "GFXTextureAgent.h" +#include "DeviceAgent.h" +#include "FramebufferAgent.h" +#include "RenderPassAgent.h" +#include "TextureAgent.h" namespace cc { namespace gfx { FramebufferAgent::~FramebufferAgent() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), FramebufferDestruct, actor, _actor, { - CC_DELETE(actor); + CC_SAFE_DELETE(actor); }); } -bool FramebufferAgent::initialize(const FramebufferInfo &info) { - _renderPass = info.renderPass; - _colorTextures = info.colorTextures; - _depthStencilTexture = info.depthStencilTexture; - +void FramebufferAgent::doInit(const FramebufferInfo &info) { FramebufferInfo actorInfo = info; for (uint i = 0u; i < info.colorTextures.size(); ++i) { if (info.colorTextures[i]) { @@ -61,20 +57,18 @@ bool FramebufferAgent::initialize(const FramebufferInfo &info) { actorInfo.renderPass = ((RenderPassAgent *)info.renderPass)->getActor(); ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), FramebufferInit, actor, getActor(), info, actorInfo, { actor->initialize(info); }); - - return true; } -void FramebufferAgent::destroy() { +void FramebufferAgent::doDestroy() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), FramebufferDestroy, actor, getActor(), { diff --git a/native/cocos/renderer/gfx-agent/GFXFramebufferAgent.h b/native/cocos/renderer/gfx-agent/FramebufferAgent.h similarity index 91% rename from native/cocos/renderer/gfx-agent/GFXFramebufferAgent.h rename to native/cocos/renderer/gfx-agent/FramebufferAgent.h index fba9bc69a7..e10fe7db9b 100644 --- a/native/cocos/renderer/gfx-agent/GFXFramebufferAgent.h +++ b/native/cocos/renderer/gfx-agent/FramebufferAgent.h @@ -25,7 +25,7 @@ #pragma once -#include "GFXAgent.h" +#include "base/Agent.h" #include "gfx-base/GFXFramebuffer.h" namespace cc { @@ -34,11 +34,11 @@ namespace gfx { class CC_DLL FramebufferAgent final : public Agent { public: using Agent::Agent; - FramebufferAgent(Device *device) = delete; ~FramebufferAgent() override; - bool initialize(const FramebufferInfo &info) override; - void destroy() override; +protected: + void doInit(const FramebufferInfo &info) override; + void doDestroy() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/GFXDescriptorSetLayoutAgent.cpp b/native/cocos/renderer/gfx-agent/GFXDescriptorSetLayoutAgent.cpp deleted file mode 100644 index d965919fd2..0000000000 --- a/native/cocos/renderer/gfx-agent/GFXDescriptorSetLayoutAgent.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** - 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. -****************************************************************************/ - -#include "base/CoreStd.h" -#include "base/threading/MessageQueue.h" - -#include "GFXDeviceAgent.h" -#include "GFXDescriptorSetLayoutAgent.h" - -namespace cc { -namespace gfx { - -DescriptorSetLayoutAgent::~DescriptorSetLayoutAgent() { - ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), - DescriptorSetLayoutDestruct, - actor, _actor, - { - CC_DELETE(actor); - }); -} - -bool DescriptorSetLayoutAgent::initialize(const DescriptorSetLayoutInfo &info) { - - _bindings = info.bindings; - uint bindingCount = _bindings.size(); - _descriptorCount = 0u; - - if (bindingCount) { - uint maxBinding = 0u; - vector flattenedIndices(bindingCount); - for (uint i = 0u; i < bindingCount; i++) { - const DescriptorSetLayoutBinding &binding = _bindings[i]; - flattenedIndices[i] = _descriptorCount; - _descriptorCount += binding.count; - if (binding.binding > maxBinding) maxBinding = binding.binding; - } - - _bindingIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); - _descriptorIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); - for (uint i = 0u; i < bindingCount; i++) { - const DescriptorSetLayoutBinding &binding = _bindings[i]; - _bindingIndices[binding.binding] = i; - _descriptorIndices[binding.binding] = flattenedIndices[i]; - } - } - - ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), - DescriptorSetLayoutInit, - actor, getActor(), - info, info, - { - actor->initialize(info); - }); - - return true; -} - -void DescriptorSetLayoutAgent::destroy() { - ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), - DescriptorSetLayoutDestroy, - actor, getActor(), - { - actor->destroy(); - }); -} - -} // namespace gfx -} // namespace cc diff --git a/native/cocos/renderer/gfx-agent/GFXTextureAgent.cpp b/native/cocos/renderer/gfx-agent/GFXTextureAgent.cpp deleted file mode 100644 index 112be7f0d5..0000000000 --- a/native/cocos/renderer/gfx-agent/GFXTextureAgent.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/**************************************************************************** - 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. -****************************************************************************/ - -#include "base/CoreStd.h" -#include "base/threading/MessageQueue.h" - -#include "GFXDeviceAgent.h" -#include "GFXTextureAgent.h" - -namespace cc { -namespace gfx { - -TextureAgent::~TextureAgent() { - ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), - TextureDestruct, - actor, _actor, - { - CC_DELETE(actor); - }); -} - -bool TextureAgent::initialize(const TextureInfo &info) { - _type = info.type; - _usage = info.usage; - _format = info.format; - _width = info.width; - _height = info.height; - _depth = info.depth; - _layerCount = info.layerCount; - _levelCount = info.levelCount; - _samples = info.samples; - _flags = info.flags; - _size = FormatSize(_format, _width, _height, _depth); - - ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), - TextureInit, - actor, getActor(), - info, info, - { - actor->initialize(info); - }); - - return true; -} - -bool TextureAgent::initialize(const TextureViewInfo &info) { - _isTextureView = true; - - if (!info.texture) { - return false; - } - - _type = info.texture->getType(); - _format = info.format; - _baseLayer = info.baseLayer; - _layerCount = info.layerCount; - _baseLevel = info.baseLevel; - _levelCount = info.levelCount; - _usage = info.texture->getUsage(); - _width = info.texture->getWidth(); - _height = info.texture->getHeight(); - _depth = info.texture->getDepth(); - _samples = info.texture->getSamples(); - _flags = info.texture->getFlags(); - _size = FormatSize(_format, _width, _height, _depth); - - ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), - TextureViewInit, - actor, getActor(), - info, info, - { - actor->initialize(info); - }); - - return true; -} - -void TextureAgent::destroy() { - ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), - TextureDestroy, - actor, getActor(), - { - actor->destroy(); - }); -} - -void TextureAgent::resize(uint width, uint height) { - ENQUEUE_MESSAGE_3( - ((DeviceAgent *)_device)->getMessageQueue(), - TextureResize, - actor, getActor(), - width, width, - height, height, - { - actor->resize(width, height); - }); -} - -} // namespace gfx -} // namespace cc diff --git a/native/cocos/renderer/gfx-agent/GFXInputAssemblerAgent.cpp b/native/cocos/renderer/gfx-agent/InputAssemblerAgent.cpp similarity index 73% rename from native/cocos/renderer/gfx-agent/GFXInputAssemblerAgent.cpp rename to native/cocos/renderer/gfx-agent/InputAssemblerAgent.cpp index b091bffc87..1d1a613030 100644 --- a/native/cocos/renderer/gfx-agent/GFXInputAssemblerAgent.cpp +++ b/native/cocos/renderer/gfx-agent/InputAssemblerAgent.cpp @@ -26,39 +26,24 @@ #include "base/CoreStd.h" #include "base/threading/MessageQueue.h" -#include "GFXBufferAgent.h" -#include "GFXDeviceAgent.h" -#include "GFXInputAssemblerAgent.h" +#include "BufferAgent.h" +#include "DeviceAgent.h" +#include "InputAssemblerAgent.h" namespace cc { namespace gfx { InputAssemblerAgent::~InputAssemblerAgent() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestruct, actor, _actor, { - CC_DELETE(actor); + CC_SAFE_DELETE(actor); }); } -bool InputAssemblerAgent::initialize(const InputAssemblerInfo &info) { - _attributes = info.attributes; - _vertexBuffers = info.vertexBuffers; - _indexBuffer = info.indexBuffer; - _indirectBuffer = info.indirectBuffer; - - if (_indexBuffer) { - _indexCount = _indexBuffer->getCount(); - _firstIndex = 0; - } else if (_vertexBuffers.size()) { - _vertexCount = _vertexBuffers[0]->getCount(); - _firstVertex = 0; - _vertexOffset = 0; - } - _attributesHash = computeAttributesHash(); - +void InputAssemblerAgent::doInit(const InputAssemblerInfo &info) { InputAssemblerInfo actorInfo = info; for (uint i = 0u; i < actorInfo.vertexBuffers.size(); ++i) { actorInfo.vertexBuffers[i] = ((BufferAgent *)actorInfo.vertexBuffers[i])->getActor(); @@ -71,20 +56,18 @@ bool InputAssemblerAgent::initialize(const InputAssemblerInfo &info) { } ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerInit, actor, getActor(), info, actorInfo, { actor->initialize(info); }); - - return true; } -void InputAssemblerAgent::destroy() { +void InputAssemblerAgent::doDestroy() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, actor, getActor(), { @@ -95,7 +78,7 @@ void InputAssemblerAgent::destroy() { void InputAssemblerAgent::setVertexCount(uint count) { _vertexCount = count; ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), InputAssemblerDestroy, + DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, actor, getActor(), count, count, { @@ -106,7 +89,7 @@ void InputAssemblerAgent::setVertexCount(uint count) { void InputAssemblerAgent::setFirstVertex(uint first) { _firstVertex = first; ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), InputAssemblerDestroy, + DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, actor, getActor(), first, first, { @@ -117,7 +100,7 @@ void InputAssemblerAgent::setFirstVertex(uint first) { void InputAssemblerAgent::setIndexCount(uint count) { _indexCount = count; ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), InputAssemblerDestroy, + DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, actor, getActor(), count, count, { @@ -128,7 +111,7 @@ void InputAssemblerAgent::setIndexCount(uint count) { void InputAssemblerAgent::setFirstIndex(uint first) { _firstIndex = first; ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), InputAssemblerDestroy, + DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, actor, getActor(), first, first, { @@ -139,7 +122,7 @@ void InputAssemblerAgent::setFirstIndex(uint first) { void InputAssemblerAgent::setVertexOffset(uint offset) { _vertexOffset = offset; ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), InputAssemblerDestroy, + DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, actor, getActor(), offset, offset, { @@ -150,7 +133,7 @@ void InputAssemblerAgent::setVertexOffset(uint offset) { void InputAssemblerAgent::setInstanceCount(uint count) { _instanceCount = count; ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), InputAssemblerDestroy, + DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, actor, getActor(), count, count, { @@ -161,7 +144,7 @@ void InputAssemblerAgent::setInstanceCount(uint count) { void InputAssemblerAgent::setFirstInstance(uint first) { _firstInstance = first; ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), InputAssemblerDestroy, + DeviceAgent::getInstance()->getMessageQueue(), InputAssemblerDestroy, actor, getActor(), first, first, { diff --git a/native/cocos/renderer/gfx-agent/GFXInputAssemblerAgent.h b/native/cocos/renderer/gfx-agent/InputAssemblerAgent.h similarity index 92% rename from native/cocos/renderer/gfx-agent/GFXInputAssemblerAgent.h rename to native/cocos/renderer/gfx-agent/InputAssemblerAgent.h index 0742c3861b..632b95aa02 100644 --- a/native/cocos/renderer/gfx-agent/GFXInputAssemblerAgent.h +++ b/native/cocos/renderer/gfx-agent/InputAssemblerAgent.h @@ -25,7 +25,7 @@ #pragma once -#include "GFXAgent.h" +#include "base/Agent.h" #include "gfx-base/GFXInputAssembler.h" namespace cc { @@ -34,12 +34,8 @@ namespace gfx { class CC_DLL InputAssemblerAgent final : public Agent { public: using Agent::Agent; - InputAssemblerAgent(Device *device) = delete; ~InputAssemblerAgent() override; - bool initialize(const InputAssemblerInfo &info) override; - void destroy() override; - void setVertexCount(uint count) override; void setFirstVertex(uint first) override; void setIndexCount(uint count) override; @@ -47,6 +43,10 @@ public: void setVertexOffset(uint offset) override; void setInstanceCount(uint count) override; void setFirstInstance(uint first) override; + +protected: + void doInit(const InputAssemblerInfo &info) override; + void doDestroy() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/GFXLinearAllocatorPool.h b/native/cocos/renderer/gfx-agent/LinearAllocatorPool.h similarity index 100% rename from native/cocos/renderer/gfx-agent/GFXLinearAllocatorPool.h rename to native/cocos/renderer/gfx-agent/LinearAllocatorPool.h diff --git a/native/cocos/renderer/gfx-agent/GFXPipelineLayoutAgent.cpp b/native/cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp similarity index 82% rename from native/cocos/renderer/gfx-agent/GFXPipelineLayoutAgent.cpp rename to native/cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp index 1b6d856c97..a89ca40315 100644 --- a/native/cocos/renderer/gfx-agent/GFXPipelineLayoutAgent.cpp +++ b/native/cocos/renderer/gfx-agent/PipelineLayoutAgent.cpp @@ -26,27 +26,24 @@ #include "base/CoreStd.h" #include "base/threading/MessageQueue.h" -#include "GFXDescriptorSetLayoutAgent.h" -#include "GFXDeviceAgent.h" -#include "GFXPipelineLayoutAgent.h" +#include "DescriptorSetLayoutAgent.h" +#include "DeviceAgent.h" +#include "PipelineLayoutAgent.h" namespace cc { namespace gfx { PipelineLayoutAgent::~PipelineLayoutAgent() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), PipelineLayoutDestruct, actor, _actor, { - CC_DELETE(actor); + CC_SAFE_DELETE(actor); }); } -bool PipelineLayoutAgent::initialize(const PipelineLayoutInfo &info) { - - _setLayouts = info.setLayouts; - +void PipelineLayoutAgent::doInit(const PipelineLayoutInfo &info) { PipelineLayoutInfo actorInfo; actorInfo.setLayouts.resize(info.setLayouts.size()); for (uint i = 0u; i < info.setLayouts.size(); i++) { @@ -54,20 +51,18 @@ bool PipelineLayoutAgent::initialize(const PipelineLayoutInfo &info) { } ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), PipelineLayoutInit, actor, getActor(), info, actorInfo, { actor->initialize(info); }); - - return true; } -void PipelineLayoutAgent::destroy() { +void PipelineLayoutAgent::doDestroy() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), PipelineLayoutDestroy, actor, getActor(), { diff --git a/native/cocos/renderer/gfx-agent/GFXPipelineLayoutAgent.h b/native/cocos/renderer/gfx-agent/PipelineLayoutAgent.h similarity index 91% rename from native/cocos/renderer/gfx-agent/GFXPipelineLayoutAgent.h rename to native/cocos/renderer/gfx-agent/PipelineLayoutAgent.h index ad17b7cfe4..488d4a13bc 100644 --- a/native/cocos/renderer/gfx-agent/GFXPipelineLayoutAgent.h +++ b/native/cocos/renderer/gfx-agent/PipelineLayoutAgent.h @@ -25,7 +25,7 @@ #pragma once -#include "GFXAgent.h" +#include "base/Agent.h" #include "gfx-base/GFXPipelineLayout.h" namespace cc { @@ -34,11 +34,11 @@ namespace gfx { class CC_DLL PipelineLayoutAgent final : public Agent { public: using Agent::Agent; - PipelineLayoutAgent(Device *device) = delete; ~PipelineLayoutAgent() override; - bool initialize(const PipelineLayoutInfo &info) override; - void destroy() override; +protected: + void doInit(const PipelineLayoutInfo &info) override; + void doDestroy() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/GFXPipelineStateAgent.cpp b/native/cocos/renderer/gfx-agent/PipelineStateAgent.cpp similarity index 72% rename from native/cocos/renderer/gfx-agent/GFXPipelineStateAgent.cpp rename to native/cocos/renderer/gfx-agent/PipelineStateAgent.cpp index 7536ea8ef8..e51f58f28a 100644 --- a/native/cocos/renderer/gfx-agent/GFXPipelineStateAgent.cpp +++ b/native/cocos/renderer/gfx-agent/PipelineStateAgent.cpp @@ -26,57 +26,44 @@ #include "base/CoreStd.h" #include "base/threading/MessageQueue.h" -#include "GFXDeviceAgent.h" -#include "GFXPipelineLayoutAgent.h" -#include "GFXPipelineStateAgent.h" -#include "GFXRenderPassAgent.h" -#include "GFXShaderAgent.h" +#include "DeviceAgent.h" +#include "PipelineLayoutAgent.h" +#include "PipelineStateAgent.h" +#include "RenderPassAgent.h" +#include "ShaderAgent.h" namespace cc { namespace gfx { PipelineStateAgent::~PipelineStateAgent() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), PipelineStateDestruct, actor, _actor, { - CC_DELETE(actor); + CC_SAFE_DELETE(actor); }); } -bool PipelineStateAgent::initialize(const PipelineStateInfo &info) { - _primitive = info.primitive; - _shader = info.shader; - _inputState = info.inputState; - _rasterizerState = info.rasterizerState; - _depthStencilState = info.depthStencilState; - _bindPoint = info.bindPoint; - _blendState = info.blendState; - _dynamicStates = info.dynamicStates; - _renderPass = info.renderPass; - _pipelineLayout = info.pipelineLayout; - +void PipelineStateAgent::doInit(const PipelineStateInfo &info) { PipelineStateInfo actorInfo = info; actorInfo.shader = ((ShaderAgent *)info.shader)->getActor(); actorInfo.pipelineLayout = ((PipelineLayoutAgent *)info.pipelineLayout)->getActor(); if (info.renderPass) actorInfo.renderPass = ((RenderPassAgent *)info.renderPass)->getActor(); ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), PipelineStateInit, actor, getActor(), info, actorInfo, { actor->initialize(info); }); - - return true; } -void PipelineStateAgent::destroy() { +void PipelineStateAgent::doDestroy() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), PipelineStateDestroy, actor, getActor(), { diff --git a/native/cocos/renderer/gfx-agent/GFXPipelineStateAgent.h b/native/cocos/renderer/gfx-agent/PipelineStateAgent.h similarity index 91% rename from native/cocos/renderer/gfx-agent/GFXPipelineStateAgent.h rename to native/cocos/renderer/gfx-agent/PipelineStateAgent.h index cab709f257..887867863a 100644 --- a/native/cocos/renderer/gfx-agent/GFXPipelineStateAgent.h +++ b/native/cocos/renderer/gfx-agent/PipelineStateAgent.h @@ -25,7 +25,7 @@ #pragma once -#include "GFXAgent.h" +#include "base/Agent.h" #include "gfx-base/GFXPipelineState.h" namespace cc { @@ -34,11 +34,11 @@ namespace gfx { class CC_DLL PipelineStateAgent final : public Agent { public: using Agent::Agent; - PipelineStateAgent(Device *device) = delete; ~PipelineStateAgent() override; - bool initialize(const PipelineStateInfo &info) override; - void destroy() override; +protected: + void doInit(const PipelineStateInfo &info) override; + void doDestroy() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/GFXQueueAgent.cpp b/native/cocos/renderer/gfx-agent/QueueAgent.cpp similarity index 83% rename from native/cocos/renderer/gfx-agent/GFXQueueAgent.cpp rename to native/cocos/renderer/gfx-agent/QueueAgent.cpp index 5b295b932a..3667b548e1 100644 --- a/native/cocos/renderer/gfx-agent/GFXQueueAgent.cpp +++ b/native/cocos/renderer/gfx-agent/QueueAgent.cpp @@ -27,42 +27,38 @@ #include "base/job-system/JobSystem.h" #include "base/threading/MessageQueue.h" -#include "GFXCommandBufferAgent.h" -#include "GFXDeviceAgent.h" -#include "GFXLinearAllocatorPool.h" -#include "GFXQueueAgent.h" +#include "CommandBufferAgent.h" +#include "DeviceAgent.h" +#include "LinearAllocatorPool.h" +#include "QueueAgent.h" namespace cc { namespace gfx { QueueAgent::~QueueAgent() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), QueueDestruct, actor, _actor, { - CC_DELETE(actor); + CC_SAFE_DELETE(actor); }); } -bool QueueAgent::initialize(const QueueInfo &info) { - _type = info.type; - +void QueueAgent::doInit(const QueueInfo &info) { ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), QueueInit, actor, getActor(), info, info, { actor->initialize(info); }); - - return true; } -void QueueAgent::destroy() { +void QueueAgent::doDestroy() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), QueueDestroy, actor, getActor(), { @@ -73,14 +69,14 @@ void QueueAgent::destroy() { void QueueAgent::submit(CommandBuffer *const *cmdBuffs, uint count) { if (!count) return; - LinearAllocatorPool *allocator = ((DeviceAgent *)_device)->getMainAllocator(); + LinearAllocatorPool *allocator = DeviceAgent::getInstance()->getMainAllocator(); CommandBuffer ** actorCmdBuffs = allocator->allocate(count); for (uint i = 0u; i < count; ++i) { actorCmdBuffs[i] = ((CommandBufferAgent *)cmdBuffs[i])->getActor(); } ENQUEUE_MESSAGE_3( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), QueueSubmit, actor, getActor(), actorCmdBuffs, actorCmdBuffs, diff --git a/native/cocos/renderer/gfx-agent/GFXQueueAgent.h b/native/cocos/renderer/gfx-agent/QueueAgent.h similarity index 91% rename from native/cocos/renderer/gfx-agent/GFXQueueAgent.h rename to native/cocos/renderer/gfx-agent/QueueAgent.h index 7290f1d9c8..f49834663b 100644 --- a/native/cocos/renderer/gfx-agent/GFXQueueAgent.h +++ b/native/cocos/renderer/gfx-agent/QueueAgent.h @@ -26,7 +26,7 @@ #pragma once #include "gfx-base/GFXQueue.h" -#include "GFXAgent.h" +#include "base/Agent.h" namespace cc { namespace gfx { @@ -36,16 +36,15 @@ public: using Agent::Agent; using Queue::submit; - QueueAgent(Device *device) = delete; ~QueueAgent() override; - bool initialize(const QueueInfo &info) override; - void destroy() override; - void submit(CommandBuffer *const *cmdBuffs, uint count) override; -private: +protected: friend class DeviceAgent; + + void doInit(const QueueInfo &info) override; + void doDestroy() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/GFXRenderPassAgent.cpp b/native/cocos/renderer/gfx-agent/RenderPassAgent.cpp similarity index 77% rename from native/cocos/renderer/gfx-agent/GFXRenderPassAgent.cpp rename to native/cocos/renderer/gfx-agent/RenderPassAgent.cpp index b49d7d0f1a..66d07f7251 100644 --- a/native/cocos/renderer/gfx-agent/GFXRenderPassAgent.cpp +++ b/native/cocos/renderer/gfx-agent/RenderPassAgent.cpp @@ -26,44 +26,36 @@ #include "base/CoreStd.h" #include "base/threading/MessageQueue.h" -#include "GFXDeviceAgent.h" -#include "GFXRenderPassAgent.h" +#include "DeviceAgent.h" +#include "RenderPassAgent.h" namespace cc { namespace gfx { RenderPassAgent::~RenderPassAgent() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), RenderPassDestruct, actor, _actor, { - CC_DELETE(actor); + CC_SAFE_DELETE(actor); }); } -bool RenderPassAgent::initialize(const RenderPassInfo &info) { - - _colorAttachments = info.colorAttachments; - _depthStencilAttachment = info.depthStencilAttachment; - _subpasses = info.subpasses; - _hash = computeHash(); - +void RenderPassAgent::doInit(const RenderPassInfo &info) { ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), RenderPassInit, actor, getActor(), info, info, { actor->initialize(info); }); - - return true; } -void RenderPassAgent::destroy() { +void RenderPassAgent::doDestroy() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), RenderPassDestroy, actor, getActor(), { diff --git a/native/cocos/renderer/gfx-agent/GFXRenderPassAgent.h b/native/cocos/renderer/gfx-agent/RenderPassAgent.h similarity index 91% rename from native/cocos/renderer/gfx-agent/GFXRenderPassAgent.h rename to native/cocos/renderer/gfx-agent/RenderPassAgent.h index e306cefd5c..8519bf6c6e 100644 --- a/native/cocos/renderer/gfx-agent/GFXRenderPassAgent.h +++ b/native/cocos/renderer/gfx-agent/RenderPassAgent.h @@ -26,7 +26,7 @@ #pragma once #include "gfx-base/GFXRenderPass.h" -#include "GFXAgent.h" +#include "base/Agent.h" namespace cc { namespace gfx { @@ -34,11 +34,11 @@ namespace gfx { class CC_DLL RenderPassAgent final : public Agent { public: using Agent::Agent; - RenderPassAgent(Device *device) = delete; ~RenderPassAgent() override; - bool initialize(const RenderPassInfo &info) override; - void destroy() override; +protected: + void doInit(const RenderPassInfo &info) override; + void doDestroy() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/GFXSamplerAgent.cpp b/native/cocos/renderer/gfx-agent/SamplerAgent.cpp similarity index 71% rename from native/cocos/renderer/gfx-agent/GFXSamplerAgent.cpp rename to native/cocos/renderer/gfx-agent/SamplerAgent.cpp index 6ca1d15a86..220d0adbd5 100644 --- a/native/cocos/renderer/gfx-agent/GFXSamplerAgent.cpp +++ b/native/cocos/renderer/gfx-agent/SamplerAgent.cpp @@ -26,51 +26,37 @@ #include "base/CoreStd.h" #include "base/threading/MessageQueue.h" -#include "GFXDescriptorSetLayoutAgent.h" -#include "GFXDeviceAgent.h" -#include "GFXSamplerAgent.h" +#include "DescriptorSetLayoutAgent.h" +#include "DeviceAgent.h" +#include "SamplerAgent.h" namespace cc { namespace gfx { SamplerAgent::~SamplerAgent() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), SamplerDestruct, actor, _actor, { - CC_DELETE(actor); + CC_SAFE_DELETE(actor); }); } -bool SamplerAgent::initialize(const SamplerInfo &info) { - - _minFilter = info.minFilter; - _magFilter = info.magFilter; - _mipFilter = info.mipFilter; - _addressU = info.addressU; - _addressV = info.addressV; - _addressW = info.addressW; - _maxAnisotropy = info.maxAnisotropy; - _cmpFunc = info.cmpFunc; - _borderColor = info.borderColor; - _mipLODBias = info.mipLODBias; - +void SamplerAgent::doInit(const SamplerInfo &info) { ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), SamplerInit, actor, getActor(), info, info, { actor->initialize(info); }); - - return true; } -void SamplerAgent::destroy() { +void SamplerAgent::doDestroy() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), SamplerDestroy, actor, getActor(), { diff --git a/native/cocos/renderer/gfx-agent/GFXSamplerAgent.h b/native/cocos/renderer/gfx-agent/SamplerAgent.h similarity index 91% rename from native/cocos/renderer/gfx-agent/GFXSamplerAgent.h rename to native/cocos/renderer/gfx-agent/SamplerAgent.h index e630a4c89f..20ee7e71a6 100644 --- a/native/cocos/renderer/gfx-agent/GFXSamplerAgent.h +++ b/native/cocos/renderer/gfx-agent/SamplerAgent.h @@ -25,7 +25,7 @@ #pragma once -#include "GFXAgent.h" +#include "base/Agent.h" #include "gfx-base/GFXSampler.h" namespace cc { @@ -34,11 +34,11 @@ namespace gfx { class CC_DLL SamplerAgent final : public Agent { public: using Agent::Agent; - SamplerAgent(Device *device) = delete; ~SamplerAgent() override; - bool initialize(const SamplerInfo &info) override; - void destroy() override; +protected: + void doInit(const SamplerInfo &info) override; + void doDestroy() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/GFXShaderAgent.cpp b/native/cocos/renderer/gfx-agent/ShaderAgent.cpp similarity index 72% rename from native/cocos/renderer/gfx-agent/GFXShaderAgent.cpp rename to native/cocos/renderer/gfx-agent/ShaderAgent.cpp index e5b1dad4d7..4c31142337 100644 --- a/native/cocos/renderer/gfx-agent/GFXShaderAgent.cpp +++ b/native/cocos/renderer/gfx-agent/ShaderAgent.cpp @@ -26,49 +26,36 @@ #include "base/CoreStd.h" #include "base/threading/MessageQueue.h" -#include "GFXDeviceAgent.h" -#include "GFXShaderAgent.h" +#include "DeviceAgent.h" +#include "ShaderAgent.h" namespace cc { namespace gfx { ShaderAgent::~ShaderAgent() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), ShaderDestruct, actor, _actor, { - CC_DELETE(actor); + CC_SAFE_DELETE(actor); }); } -bool ShaderAgent::initialize(const ShaderInfo &info) { - _name = info.name; - _stages = info.stages; - _attributes = info.attributes; - _blocks = info.blocks; - _buffers = info.buffers; - _samplerTextures = info.samplerTextures; - _samplers = info.samplers; - _textures = info.textures; - _images = info.images; - _subpassInputs = info.subpassInputs; - +void ShaderAgent::doInit(const ShaderInfo &info) { ENQUEUE_MESSAGE_2( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), ShaderInit, actor, getActor(), info, info, { actor->initialize(info); }); - - return true; } -void ShaderAgent::destroy() { +void ShaderAgent::doDestroy() { ENQUEUE_MESSAGE_1( - ((DeviceAgent *)_device)->getMessageQueue(), + DeviceAgent::getInstance()->getMessageQueue(), ShaderDestroy, actor, getActor(), { diff --git a/native/cocos/renderer/gfx-agent/GFXShaderAgent.h b/native/cocos/renderer/gfx-agent/ShaderAgent.h similarity index 91% rename from native/cocos/renderer/gfx-agent/GFXShaderAgent.h rename to native/cocos/renderer/gfx-agent/ShaderAgent.h index 955bf48640..6d228c1006 100644 --- a/native/cocos/renderer/gfx-agent/GFXShaderAgent.h +++ b/native/cocos/renderer/gfx-agent/ShaderAgent.h @@ -25,7 +25,7 @@ #pragma once -#include "GFXAgent.h" +#include "base/Agent.h" #include "gfx-base/GFXShader.h" namespace cc { @@ -34,11 +34,11 @@ namespace gfx { class CC_DLL ShaderAgent final : public Agent { public: using Agent::Agent; - ShaderAgent(Device *device) = delete; ~ShaderAgent() override; - bool initialize(const ShaderInfo &info) override; - void destroy() override; +protected: + void doInit(const ShaderInfo &info) override; + void doDestroy() override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-agent/TextureAgent.cpp b/native/cocos/renderer/gfx-agent/TextureAgent.cpp new file mode 100644 index 0000000000..3394db27e8 --- /dev/null +++ b/native/cocos/renderer/gfx-agent/TextureAgent.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "base/CoreStd.h" +#include "base/threading/MessageQueue.h" + +#include "DeviceAgent.h" +#include "TextureAgent.h" + +namespace cc { +namespace gfx { + +TextureAgent::~TextureAgent() { + ENQUEUE_MESSAGE_1( + DeviceAgent::getInstance()->getMessageQueue(), + TextureDestruct, + actor, _actor, + { + CC_SAFE_DELETE(actor); + }); +} + +void TextureAgent::doInit(const TextureInfo &info) { + ENQUEUE_MESSAGE_2( + DeviceAgent::getInstance()->getMessageQueue(), + TextureInit, + actor, getActor(), + info, info, + { + actor->initialize(info); + }); +} + +void TextureAgent::doInit(const TextureViewInfo &info) { + TextureViewInfo actorInfo = info; + actorInfo.texture = ((TextureAgent *)info.texture)->getActor(); + + ENQUEUE_MESSAGE_2( + DeviceAgent::getInstance()->getMessageQueue(), + TextureViewInit, + actor, getActor(), + info, actorInfo, + { + actor->initialize(info); + }); +} + +void TextureAgent::doDestroy() { + ENQUEUE_MESSAGE_1( + DeviceAgent::getInstance()->getMessageQueue(), + TextureDestroy, + actor, getActor(), + { + actor->destroy(); + }); +} + +void TextureAgent::doResize(uint width, uint height) { + ENQUEUE_MESSAGE_3( + DeviceAgent::getInstance()->getMessageQueue(), + TextureResize, + actor, getActor(), + width, width, + height, height, + { + actor->resize(width, height); + }); +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-agent/GFXTextureAgent.h b/native/cocos/renderer/gfx-agent/TextureAgent.h similarity index 86% rename from native/cocos/renderer/gfx-agent/GFXTextureAgent.h rename to native/cocos/renderer/gfx-agent/TextureAgent.h index 66aaf69157..eb8728b570 100644 --- a/native/cocos/renderer/gfx-agent/GFXTextureAgent.h +++ b/native/cocos/renderer/gfx-agent/TextureAgent.h @@ -25,7 +25,7 @@ #pragma once -#include "GFXAgent.h" +#include "base/Agent.h" #include "gfx-base/GFXTexture.h" namespace cc { @@ -34,13 +34,13 @@ namespace gfx { class CC_DLL TextureAgent final : public Agent { public: using Agent::Agent; - TextureAgent(Device *device) = delete; ~TextureAgent() override; - bool initialize(const TextureInfo &info) override; - bool initialize(const TextureViewInfo &info) override; - void destroy() override; - void resize(uint width, uint height) override; +protected: + void doInit(const TextureInfo &info) override; + void doInit(const TextureViewInfo &info) override; + void doDestroy() override; + void doResize(uint width, uint height) override; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-base/GFXBuffer.cpp b/native/cocos/renderer/gfx-base/GFXBuffer.cpp index 7232a0f169..fb0d60324c 100644 --- a/native/cocos/renderer/gfx-base/GFXBuffer.cpp +++ b/native/cocos/renderer/gfx-base/GFXBuffer.cpp @@ -26,14 +26,14 @@ #include "base/CoreStd.h" #include "GFXBuffer.h" +#include "GFXDevice.h" #include "GFXObject.h" namespace cc { namespace gfx { -Buffer::Buffer(Device *device) -: GFXObject(ObjectType::BUFFER), - _device(device) { +Buffer::Buffer() +: GFXObject(ObjectType::BUFFER) { } Buffer::~Buffer() { @@ -48,5 +48,52 @@ uint Buffer::computeHash(const BufferInfo &info) { return seed; } +void Buffer::initialize(const BufferInfo &info) { + _usage = info.usage; + _memUsage = info.memUsage; + _size = info.size; + _flags = info.flags; + _stride = std::max(info.stride, 1u); + _count = _size / _stride; + + Device::getInstance()->getMemoryStatus().bufferSize += _size; + + doInit(info); +} + +void Buffer::initialize(const BufferViewInfo &info) { + _usage = info.buffer->getUsage(); + _memUsage = info.buffer->getMemUsage(); + _flags = info.buffer->getFlags(); + _offset = info.offset; + _size = _stride = info.range; + _count = 1u; + _isBufferView = true; + + doInit(info); +} + +void Buffer::destroy() { + doDestroy(); + + Device::getInstance()->getMemoryStatus().bufferSize -= _size; + + _offset = _size = _stride = _count = 0u; +} + +void Buffer::resize(uint size) { + CCASSERT(!_isBufferView, "Cannot resize buffer views"); + + if (size != _size) { + doResize(size); + Device::getInstance()->getMemoryStatus().bufferSize -= _size; + + _size = size; + _count = size / _stride; + + Device::getInstance()->getMemoryStatus().bufferSize += _size; + } +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXBuffer.h b/native/cocos/renderer/gfx-base/GFXBuffer.h index 0c1539fc4c..1b402cab4e 100644 --- a/native/cocos/renderer/gfx-base/GFXBuffer.h +++ b/native/cocos/renderer/gfx-base/GFXBuffer.h @@ -32,18 +32,18 @@ namespace gfx { class CC_DLL Buffer : public GFXObject { public: - Buffer(Device *device); + Buffer(); virtual ~Buffer(); static uint computeHash(const BufferInfo &info); - virtual bool initialize(const BufferInfo &info) = 0; - virtual bool initialize(const BufferViewInfo &info) = 0; - virtual void destroy() = 0; - virtual void resize(uint size) = 0; - virtual void update(void *buffer, uint size) = 0; + void initialize(const BufferInfo &info); + void initialize(const BufferViewInfo &info); + void resize(uint size); + void destroy(); + + virtual void update(void *buffer, uint size) = 0; - CC_INLINE Device * getDevice() const { return _device; } CC_INLINE BufferUsage getUsage() const { return _usage; } CC_INLINE MemoryUsage getMemUsage() const { return _memUsage; } CC_INLINE uint getStride() const { return _stride; } @@ -52,7 +52,11 @@ public: CC_INLINE BufferFlags getFlags() const { return _flags; } protected: - Device * _device = nullptr; + virtual void doInit(const BufferInfo &info) = 0; + virtual void doInit(const BufferViewInfo &info) = 0; + virtual void doResize(uint size) = 0; + virtual void doDestroy() = 0; + BufferUsage _usage = BufferUsageBit::NONE; MemoryUsage _memUsage = MemoryUsageBit::NONE; uint _stride = 0u; @@ -60,7 +64,6 @@ protected: uint _size = 0u; uint _offset = 0u; BufferFlags _flags = BufferFlagBit::NONE; - uint8_t * _buffer = nullptr; bool _isBufferView = false; }; diff --git a/native/cocos/renderer/gfx-base/GFXCommandBuffer.cpp b/native/cocos/renderer/gfx-base/GFXCommandBuffer.cpp index fba6440ae1..50aebcb63b 100644 --- a/native/cocos/renderer/gfx-base/GFXCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-base/GFXCommandBuffer.cpp @@ -31,13 +31,26 @@ namespace cc { namespace gfx { -CommandBuffer::CommandBuffer(Device *device) -: GFXObject(ObjectType::COMMAND_BUFFER), - _device(device) { +CommandBuffer::CommandBuffer() +: GFXObject(ObjectType::COMMAND_BUFFER) { } CommandBuffer::~CommandBuffer() { } +void CommandBuffer::initialize(const CommandBufferInfo& info) { + _type = info.type; + _queue = info.queue; + + doInit(info); +} + +void CommandBuffer::destroy() { + doDestroy(); + + _type = CommandBufferType::PRIMARY; + _queue = nullptr; +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXCommandBuffer.h b/native/cocos/renderer/gfx-base/GFXCommandBuffer.h index 81cf9be232..15399a707c 100644 --- a/native/cocos/renderer/gfx-base/GFXCommandBuffer.h +++ b/native/cocos/renderer/gfx-base/GFXCommandBuffer.h @@ -23,109 +23,165 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_COMMAND_BUFFER_H_ -#define CC_CORE_GFX_COMMAND_BUFFER_H_ +#pragma once -#include "GFXObject.h" #include "GFXBuffer.h" +#include "GFXObject.h" namespace cc { namespace gfx { class CC_DLL CommandBuffer : public GFXObject { public: - CommandBuffer(Device *device); + CommandBuffer(); virtual ~CommandBuffer(); public: - virtual bool initialize(const CommandBufferInfo &info) = 0; - virtual void destroy() = 0; - virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) = 0; - virtual void end() = 0; + 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, int 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, int ref, uint mask) = 0; - virtual void draw(InputAssembler *ia) = 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 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, int ref, uint mask) = 0; + virtual void draw(InputAssembler *ia) = 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; - CC_INLINE void begin() { begin(nullptr, 0, nullptr); } - // secondary command buffer specifics - CC_INLINE void begin(RenderPass *renderPass) { begin(renderPass, 0, nullptr); } - CC_INLINE void begin(RenderPass *renderPass, uint subpass) { begin(renderPass, subpass, nullptr); } + inline void begin(); + inline void begin(RenderPass *renderPass); + inline void begin(RenderPass *renderPass, uint subpass); - CC_INLINE void updateBuffer(Buffer *buff, const void *data) { updateBuffer(buff, data, buff->getSize()); } - CC_INLINE void execute(CommandBufferList &cmdBuffs, uint32_t count) { execute(cmdBuffs.data(), count); } - CC_INLINE void bindDescriptorSet(uint set, DescriptorSet *descriptorSet) { bindDescriptorSet(set, descriptorSet, 0, nullptr); } - CC_INLINE void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, const vector &dynamicOffsets) { - bindDescriptorSet(set, descriptorSet, static_cast(dynamicOffsets.size()), dynamicOffsets.data()); - } - CC_INLINE void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil, const CommandBufferList &secondaryCBs) { - beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, secondaryCBs.data(), static_cast(secondaryCBs.size())); - } - CC_INLINE void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil) { - beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, nullptr, 0); - } - CC_INLINE void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) { - beginRenderPass(renderPass, fbo, renderArea, colors, depth, stencil, nullptr, 0); - } - CC_INLINE void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { - copyBuffersToTexture(buffers.data(), texture, regions.data(), static_cast(regions.size())); - } - CC_INLINE void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlitList ®ions, Filter filter) { - blitTexture(srcTexture, dstTexture, regions.data(), static_cast(regions.size()), filter); - } - CC_INLINE void pipelineBarrier(const GlobalBarrier *barrier) { pipelineBarrier(barrier, nullptr, nullptr, 0u); } - CC_INLINE void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrierList &textureBarriers, const TextureList &textures) { - pipelineBarrier(barrier, textureBarriers.data(), textures.data(), static_cast(textureBarriers.size())); - } + inline void updateBuffer(Buffer *buff, const void *data); - CC_INLINE void bindDescriptorSetForJS(uint set, DescriptorSet *descriptorSet) { - bindDescriptorSet(set, descriptorSet, 0, nullptr); - } - CC_INLINE void bindDescriptorSetForJS(uint set, DescriptorSet *descriptorSet, const vector &dynamicOffsets) { - bindDescriptorSet(set, descriptorSet, static_cast(dynamicOffsets.size()), dynamicOffsets.data()); - } - CC_INLINE void beginRenderPassForJS(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil, const CommandBufferList &secondaryCBs) { - beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, secondaryCBs.data(), static_cast(secondaryCBs.size())); - } - CC_INLINE void beginRenderPassForJS(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil) { - beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, nullptr, 0); - } + inline void execute(CommandBufferList &cmdBuffs, uint32_t count); - CC_INLINE Device *getDevice() const { return _device; } - CC_INLINE Queue *getQueue() const { return _queue; } - CC_INLINE CommandBufferType getType() const { return _type; } + inline void bindDescriptorSet(uint set, DescriptorSet *descriptorSet); + inline void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, const vector &dynamicOffsets); + + inline void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil, const CommandBufferList &secondaryCBs); + inline void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil); + inline void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil); + + inline void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions); + + inline void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlitList ®ions, Filter filter); + + inline void pipelineBarrier(const GlobalBarrier *barrier); + inline void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrierList &textureBarriers, const TextureList &textures); + + inline void bindDescriptorSetForJS(uint set, DescriptorSet *descriptorSet); + inline void bindDescriptorSetForJS(uint set, DescriptorSet *descriptorSet, const vector &dynamicOffsets); + inline void beginRenderPassForJS(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil, const CommandBufferList &secondaryCBs); + inline void beginRenderPassForJS(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil); + + 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; } protected: - Device *_device = nullptr; - Queue *_queue = nullptr; - CommandBufferType _type = CommandBufferType::PRIMARY; + virtual void doInit(const CommandBufferInfo &info) = 0; + virtual void doDestroy() = 0; + + Queue * _queue = nullptr; + CommandBufferType _type = CommandBufferType::PRIMARY; uint32_t _numDrawCalls = 0; uint32_t _numInstances = 0; uint32_t _numTriangles = 0; }; +////////////////////////////////////////////////////////////////////////// + +void CommandBuffer::begin() { + begin(nullptr, 0, nullptr); +} + +void CommandBuffer::begin(RenderPass *renderPass) { + begin(renderPass, 0, nullptr); +} + +void CommandBuffer::begin(RenderPass *renderPass, uint subpass) { + begin(renderPass, subpass, nullptr); +} + +void CommandBuffer::updateBuffer(Buffer *buff, const void *data) { + updateBuffer(buff, data, buff->getSize()); +} + +void CommandBuffer::execute(CommandBufferList &cmdBuffs, uint32_t count) { + execute(cmdBuffs.data(), count); +} + +void CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet) { + bindDescriptorSet(set, descriptorSet, 0, nullptr); +} + +void CommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet, const vector &dynamicOffsets) { + bindDescriptorSet(set, descriptorSet, static_cast(dynamicOffsets.size()), dynamicOffsets.data()); +} + +void CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil, const CommandBufferList &secondaryCBs) { + beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, secondaryCBs.data(), static_cast(secondaryCBs.size())); +} + +void CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int 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, int stencil) { + beginRenderPass(renderPass, fbo, renderArea, colors, depth, stencil, nullptr, 0); +} + +void CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList ®ions) { + copyBuffersToTexture(buffers.data(), texture, regions.data(), static_cast(regions.size())); +} + +void CommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlitList ®ions, Filter filter) { + blitTexture(srcTexture, dstTexture, regions.data(), static_cast(regions.size()), filter); +} + +void CommandBuffer::pipelineBarrier(const GlobalBarrier *barrier) { + pipelineBarrier(barrier, nullptr, nullptr, 0u); +} + +void CommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrierList &textureBarriers, const TextureList &textures) { + pipelineBarrier(barrier, textureBarriers.data(), textures.data(), static_cast(textureBarriers.size())); +} + +void CommandBuffer::bindDescriptorSetForJS(uint set, DescriptorSet *descriptorSet) { + bindDescriptorSet(set, descriptorSet, 0, nullptr); +} + +void CommandBuffer::bindDescriptorSetForJS(uint set, DescriptorSet *descriptorSet, const vector &dynamicOffsets) { + bindDescriptorSet(set, descriptorSet, static_cast(dynamicOffsets.size()), dynamicOffsets.data()); +} + +void CommandBuffer::beginRenderPassForJS(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil, const CommandBufferList &secondaryCBs) { + beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, secondaryCBs.data(), static_cast(secondaryCBs.size())); +} + +void CommandBuffer::beginRenderPassForJS(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const ColorList &colors, float depth, int stencil) { + beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil, nullptr, 0); +} + } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_COMMAND_ALLOCATOR_H_ diff --git a/native/cocos/renderer/gfx-base/GFXContext.cpp b/native/cocos/renderer/gfx-base/GFXContext.cpp index fc2e307d3f..77d2c7aaf1 100644 --- a/native/cocos/renderer/gfx-base/GFXContext.cpp +++ b/native/cocos/renderer/gfx-base/GFXContext.cpp @@ -30,12 +30,22 @@ namespace cc { namespace gfx { -Context::Context(Device *device) -: _device(device) { +Context::Context() { } Context::~Context() { } +bool Context::initialize(const ContextInfo& info) { + _vsyncMode = info.vsyncMode; + _windowHandle = info.windowHandle; + + return doInit(info); +} + +void Context::destroy() { + doDestroy(); +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXContext.h b/native/cocos/renderer/gfx-base/GFXContext.h index 3755b2602b..e29e476b50 100644 --- a/native/cocos/renderer/gfx-base/GFXContext.h +++ b/native/cocos/renderer/gfx-base/GFXContext.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_CONTEXT_H_ -#define CC_CORE_GFX_CONTEXT_H_ +#pragma once #include "GFXObject.h" @@ -33,30 +32,29 @@ namespace gfx { class CC_DLL Context : public Object { public: - Context(Device *device); + Context(); virtual ~Context(); -public: - virtual bool initialize(const ContextInfo &info) = 0; - virtual void destroy() = 0; + bool initialize(const ContextInfo &info); + void destroy(); + virtual void present() = 0; - CC_INLINE Device *getDevice() const { return _device; } - CC_INLINE Context *getSharedContext() const { return _sharedContext; } + CC_INLINE Context * getSharedContext() const { return _sharedContext; } CC_INLINE VsyncMode getVsyncMode() const { return _vsyncMode; } - CC_INLINE Format getColorFormat() const { return _colorFmt; } - CC_INLINE Format getDepthStencilFormat() const { return _depthStencilFmt; } + CC_INLINE Format getColorFormat() const { return _colorFmt; } + CC_INLINE Format getDepthStencilFormat() const { return _depthStencilFmt; } protected: - Device *_device = nullptr; - uintptr_t _windowHandle = 0; - Context *_sharedContext = nullptr; - VsyncMode _vsyncMode = VsyncMode::OFF; - Format _colorFmt = Format::UNKNOWN; - Format _depthStencilFmt = Format::UNKNOWN; + virtual bool doInit(const ContextInfo &info) = 0; + virtual void doDestroy() = 0; + + uintptr_t _windowHandle = 0; + Context * _sharedContext = nullptr; + VsyncMode _vsyncMode = VsyncMode::OFF; + Format _colorFmt = Format::UNKNOWN; + Format _depthStencilFmt = Format::UNKNOWN; }; } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_CONTEXT_H_ diff --git a/native/cocos/renderer/gfx-base/GFXDef-common.h b/native/cocos/renderer/gfx-base/GFXDef-common.h index 32c73fad48..373d28289c 100644 --- a/native/cocos/renderer/gfx-base/GFXDef-common.h +++ b/native/cocos/renderer/gfx-base/GFXDef-common.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_DEF_COMMON_H_ -#define CC_CORE_GFX_DEF_COMMON_H_ +#pragma once #include "base/TypeDef.h" #include "base/memory/Memory.h" @@ -401,8 +400,7 @@ using BufferUsage = BufferUsageBit; CC_ENUM_OPERATORS(BufferUsageBit); enum class BufferFlagBit : FlagBits { - NONE = 0, - BAKUP_BUFFER = 0x4, + NONE = 0, }; using BufferFlags = BufferFlagBit; CC_ENUM_OPERATORS(BufferFlagBit); @@ -449,8 +447,7 @@ CC_ENUM_OPERATORS(TextureUsageBit); enum class TextureFlagBit : FlagBits { NONE = 0, GEN_MIPMAP = 0x1, - BAKUP_BUFFER = 0x2, - IMMUTABLE = 0x4, + IMMUTABLE = 0x2, }; using TextureFlags = TextureFlagBit; CC_ENUM_OPERATORS(TextureFlagBit); @@ -717,13 +714,15 @@ struct DeviceCaps { uint maxUniformBlockSize = 0u; uint maxTextureSize = 0u; uint maxCubeMapTextureSize = 0u; - uint uboOffsetAlignment = 0u; uint depthBits = 0u; uint stencilBits = 0u; + uint uboOffsetAlignment = 1u; + uint maxComputeSharedMemorySize = 0u; uint maxComputeWorkGroupInvocations = 0u; Size maxComputeWorkGroupSize; Size maxComputeWorkGroupCount; + float clipSpaceMinZ = -1.0f; float screenSpaceSignY = 1.0f; float UVSpaceSignY = -1.0f; @@ -1237,5 +1236,3 @@ struct MemoryStatus { } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_DEF_COMMON_H_ diff --git a/native/cocos/renderer/gfx-base/GFXDef.h b/native/cocos/renderer/gfx-base/GFXDef.h index 5c87410a02..0f21f44c2a 100644 --- a/native/cocos/renderer/gfx-base/GFXDef.h +++ b/native/cocos/renderer/gfx-base/GFXDef.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_DEF_H_ -#define CC_CORE_GFX_DEF_H_ +#pragma once #include "GFXDef-common.h" @@ -61,25 +60,9 @@ struct DeviceInfo { uint height = 0; uint nativeWidth = 0; uint nativeHeight = 0; - Context * sharedCtx = nullptr; BindingMappingInfo bindingMappingInfo; }; -struct WindowInfo { - String title; - int left = 0; - int top = 0; - uint width = 800; - uint height = 600; - Format colorFmt = Format::UNKNOWN; - Format depthStencilFmt = Format::UNKNOWN; - bool isOffscreen = false; - bool isFullscreen = false; - VsyncMode vsyncMode = VsyncMode::OFF; - uintptr_t windowHandle = 0; - RenderPass *renderPass = nullptr; -}; - struct ContextInfo { uintptr_t windowHandle = 0; Context * sharedCtx = nullptr; @@ -100,5 +83,3 @@ extern uint FormatSurfaceSize(Format format, uint width, uint height, uint depth } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_DEF_H_ diff --git a/native/cocos/renderer/gfx-base/GFXDescriptorSet.cpp b/native/cocos/renderer/gfx-base/GFXDescriptorSet.cpp index 48f8f3d48b..f22eb9dc91 100644 --- a/native/cocos/renderer/gfx-base/GFXDescriptorSet.cpp +++ b/native/cocos/renderer/gfx-base/GFXDescriptorSet.cpp @@ -32,14 +32,33 @@ namespace cc { namespace gfx { -DescriptorSet::DescriptorSet(Device *device) -: GFXObject(ObjectType::DESCRIPTOR_SET), - _device(device) { +DescriptorSet::DescriptorSet() +: GFXObject(ObjectType::DESCRIPTOR_SET) { } DescriptorSet::~DescriptorSet() { } +void DescriptorSet::initialize(const DescriptorSetInfo& info) { + _layout = info.layout; + uint descriptorCount = _layout->getDescriptorCount(); + _buffers.resize(descriptorCount); + _textures.resize(descriptorCount); + _samplers.resize(descriptorCount); + + doInit(info); +} + +void DescriptorSet::destroy() { + doDestroy(); + + _layout = nullptr; + // have to clear these or else it might not be properly updated when reused + _buffers.clear(); + _textures.clear(); + _samplers.clear(); +} + void DescriptorSet::bindBuffer(uint binding, Buffer *buffer, uint index) { const vector & bindingIndices = _layout->getBindingIndices(); const DescriptorSetLayoutBindingList &bindings = _layout->getBindings(); diff --git a/native/cocos/renderer/gfx-base/GFXDescriptorSet.h b/native/cocos/renderer/gfx-base/GFXDescriptorSet.h index aff044ebb5..6bd48b93e3 100644 --- a/native/cocos/renderer/gfx-base/GFXDescriptorSet.h +++ b/native/cocos/renderer/gfx-base/GFXDescriptorSet.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_DESCRIPTOR_SET_H_ -#define CC_CORE_GFX_DESCRIPTOR_SET_H_ +#pragma once #include "GFXObject.h" @@ -33,12 +32,13 @@ namespace gfx { class CC_DLL DescriptorSet : public GFXObject { public: - DescriptorSet(Device *device); + DescriptorSet(); virtual ~DescriptorSet(); public: - virtual bool initialize(const DescriptorSetInfo &info) = 0; - virtual void destroy() = 0; + void initialize(const DescriptorSetInfo &info); + void destroy(); + virtual void update() = 0; virtual void bindBuffer(uint binding, Buffer *buffer, uint index); @@ -50,30 +50,28 @@ public: bool bindTextureJSB(uint binding, Texture *texture, uint index); bool bindSamplerJSB(uint binding, Sampler *sampler, uint index); - Buffer *getBuffer(uint binding, uint index) const; + Buffer * getBuffer(uint binding, uint index) const; Texture *getTexture(uint binding, uint index) const; Sampler *getSampler(uint binding, uint index) const; - CC_INLINE Device *getDevice() const { return _device; } - CC_INLINE void bindBuffer(uint binding, Buffer *buffer) { bindBuffer(binding, buffer, 0u); } - CC_INLINE void bindTexture(uint binding, Texture *texture) { bindTexture(binding, texture, 0u); } - CC_INLINE void bindSampler(uint binding, Sampler *sampler) { bindSampler(binding, sampler, 0u); } + CC_INLINE void bindBuffer(uint binding, Buffer *buffer) { bindBuffer(binding, buffer, 0u); } + CC_INLINE void bindTexture(uint binding, Texture *texture) { bindTexture(binding, texture, 0u); } + CC_INLINE void bindSampler(uint binding, Sampler *sampler) { bindSampler(binding, sampler, 0u); } CC_INLINE Buffer *getBuffer(uint binding) const { return getBuffer(binding, 0u); } CC_INLINE Texture *getTexture(uint binding) const { return getTexture(binding, 0u); } CC_INLINE Sampler *getSampler(uint binding) const { return getSampler(binding, 0u); } protected: - Device *_device = nullptr; + virtual void doInit(const DescriptorSetInfo &info) = 0; + virtual void doDestroy() = 0; DescriptorSetLayout *_layout; - BufferList _buffers; - TextureList _textures; - SamplerList _samplers; + BufferList _buffers; + TextureList _textures; + SamplerList _samplers; bool _isDirty = false; }; } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_DESCRIPTOR_SET_H_ diff --git a/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.cpp b/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.cpp index 8202345d37..0c77c63db7 100644 --- a/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.cpp @@ -31,12 +31,48 @@ namespace cc { namespace gfx { -DescriptorSetLayout::DescriptorSetLayout(Device *device) -: GFXObject(ObjectType::DESCRIPTOR_SET_LAYOUT), _device(device) { +DescriptorSetLayout::DescriptorSetLayout() +: GFXObject(ObjectType::DESCRIPTOR_SET_LAYOUT) { } DescriptorSetLayout::~DescriptorSetLayout() { } +void DescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { + _bindings = info.bindings; + uint bindingCount = _bindings.size(); + _descriptorCount = 0u; + + if (bindingCount) { + uint maxBinding = 0u; + vector flattenedIndices(bindingCount); + for (uint i = 0u; i < bindingCount; i++) { + const DescriptorSetLayoutBinding &binding = _bindings[i]; + flattenedIndices[i] = _descriptorCount; + _descriptorCount += binding.count; + if (binding.binding > maxBinding) maxBinding = binding.binding; + } + + _bindingIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); + _descriptorIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); + for (uint i = 0u; i < bindingCount; i++) { + const DescriptorSetLayoutBinding &binding = _bindings[i]; + _bindingIndices[binding.binding] = i; + _descriptorIndices[binding.binding] = flattenedIndices[i]; + } + } + + doInit(info); +} + +void DescriptorSetLayout::destroy() { + doDestroy(); + + _bindings.clear(); + _descriptorCount = 0u; + _bindingIndices.clear(); + _descriptorIndices.clear(); +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.h b/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.h index 2aa3738e5f..30222459ff 100644 --- a/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.h +++ b/native/cocos/renderer/gfx-base/GFXDescriptorSetLayout.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_DESCRIPTOR_SET_LAYOUT_H_ -#define CC_CORE_GFX_DESCRIPTOR_SET_LAYOUT_H_ +#pragma once #include "GFXObject.h" @@ -33,28 +32,26 @@ namespace gfx { class CC_DLL DescriptorSetLayout : public GFXObject { public: - DescriptorSetLayout(Device *device); + DescriptorSetLayout(); virtual ~DescriptorSetLayout(); -public: - virtual bool initialize(const DescriptorSetLayoutInfo &info) = 0; - virtual void destroy() = 0; + void initialize(const DescriptorSetLayoutInfo &info); + void destroy(); - CC_INLINE Device *getDevice() const { return _device; } CC_INLINE const DescriptorSetLayoutBindingList &getBindings() const { return _bindings; } CC_INLINE const vector &getBindingIndices() const { return _bindingIndices; } CC_INLINE const vector &getDescriptorIndices() const { return _descriptorIndices; } - CC_INLINE const uint getDescriptorCount() const { return _descriptorCount; } + CC_INLINE const uint getDescriptorCount() const { return _descriptorCount; } protected: - Device *_device = nullptr; + virtual void doInit(const DescriptorSetLayoutInfo &info) = 0; + virtual void doDestroy() = 0; + DescriptorSetLayoutBindingList _bindings; - uint _descriptorCount = 0u; - vector _bindingIndices; - vector _descriptorIndices; + uint _descriptorCount = 0u; + vector _bindingIndices; + vector _descriptorIndices; }; } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_DESCRIPTOR_SET_LAYOUT_H_ diff --git a/native/cocos/renderer/gfx-base/GFXDevice.cpp b/native/cocos/renderer/gfx-base/GFXDevice.cpp index e31825d2b4..58e52a6c4b 100644 --- a/native/cocos/renderer/gfx-base/GFXDevice.cpp +++ b/native/cocos/renderer/gfx-base/GFXDevice.cpp @@ -41,23 +41,10 @@ Device *Device::getInstance() { Device::Device() { Device::_instance = this; memset(_features, 0, sizeof(_features)); - //EventDispatcher::addCustomEventListener(EVENT_RESTART_VM, [=](const CustomEvent&) -> void { - // // FIXME: wait & flush all pending gfx commands - // Device::_instance->destroy(); - //}); } Device::~Device() { - // On Android, engine will check vulkan, gles3, gles2 compatibility in sequence. - // Device::_instance will be the supported device, it may not be equal to this. - // For example, if a vulkan is not supported and gles3 is supported by a Android - // device. Then the function invoking sequence is: - // - new VKDevice() -> Device::_instance == VKDevice - // - GLES3Device() -> Device::_instance == GLES3Device - // delete VKDevice -> Device::_instance != this - if (this == Device::_instance) { - Device::_instance = nullptr; - } + Device::_instance = nullptr; } Format Device::getColorFormat() const { @@ -68,5 +55,31 @@ Format Device::getDepthStencilFormat() const { return _context->getDepthStencilFormat(); } +bool Device::initialize(const DeviceInfo &info) { + _width = info.width; + _height = info.height; + _nativeWidth = info.nativeWidth; + _nativeHeight = info.nativeHeight; + _windowHandle = info.windowHandle; + + _bindingMappingInfo = info.bindingMappingInfo; + if (_bindingMappingInfo.bufferOffsets.empty()) { + _bindingMappingInfo.bufferOffsets.push_back(0); + } + if (_bindingMappingInfo.samplerOffsets.empty()) { + _bindingMappingInfo.samplerOffsets.push_back(0); + } + + return doInit(info); +} + +void Device::destroy() { + doDestroy(); + + _bindingMappingInfo.bufferOffsets.clear(); + _bindingMappingInfo.samplerOffsets.clear(); + _width = _height = _nativeWidth = _nativeHeight = _windowHandle = 0u; +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXDevice.h b/native/cocos/renderer/gfx-base/GFXDevice.h index 074207d7f5..32a7cc6cb2 100644 --- a/native/cocos/renderer/gfx-base/GFXDevice.h +++ b/native/cocos/renderer/gfx-base/GFXDevice.h @@ -23,17 +23,16 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_DEVICE_H_ -#define CC_CORE_GFX_DEVICE_H_ +#pragma once #include "GFXBuffer.h" #include "GFXCommandBuffer.h" -#include "GFXObject.h" #include "GFXDescriptorSet.h" #include "GFXDescriptorSetLayout.h" #include "GFXFramebuffer.h" #include "GFXGlobalBarrier.h" #include "GFXInputAssembler.h" +#include "GFXObject.h" #include "GFXPipelineLayout.h" #include "GFXPipelineState.h" #include "GFXQueue.h" @@ -50,18 +49,18 @@ class CC_DLL Device : public Object { public: static Device *getInstance(); - Device(); - Device(Device *device) : Device() {} virtual ~Device(); - virtual bool initialize(const DeviceInfo &info) = 0; - virtual void destroy() = 0; - virtual void resize(uint width, uint height) = 0; - virtual void acquire() = 0; - virtual void present() = 0; + bool initialize(const DeviceInfo &info); + void destroy(); + + virtual void resize(uint width, uint height) = 0; + virtual void acquire() = 0; + virtual void present() = 0; + + virtual void flushCommands(CommandBuffer *const *cmdBuffs, uint count) {} + virtual void setMultithreaded(bool multithreaded) {} - virtual void flushCommands(CommandBuffer *const *cmdBuffs, uint count) {} - virtual void setMultithreaded(bool multithreaded) {} virtual SurfaceTransform getSurfaceTransform() const { return _transform; } virtual uint getWidth() const { return _width; } virtual uint getHeight() const { return _height; } @@ -72,117 +71,54 @@ public: virtual uint getNumInstances() const { return _numInstances; } virtual uint getNumTris() const { return _numTriangles; } - CC_INLINE CommandBuffer *createCommandBuffer(const CommandBufferInfo &info) { - CommandBuffer *res = doCreateCommandBuffer(info, false); - res->initialize(info); - return res; - } - CC_INLINE Queue *createQueue(const QueueInfo &info) { - Queue *res = createQueue(); - res->initialize(info); - return res; - } - CC_INLINE Buffer *createBuffer(const BufferInfo &info) { - Buffer *res = createBuffer(); - res->initialize(info); - return res; - } - CC_INLINE Buffer *createBuffer(const BufferViewInfo &info) { - Buffer *res = createBuffer(); - res->initialize(info); - return res; - } - CC_INLINE Texture *createTexture(const TextureInfo &info) { - Texture *res = createTexture(); - res->initialize(info); - return res; - } - CC_INLINE Texture *createTexture(const TextureViewInfo &info) { - Texture *res = createTexture(); - res->initialize(info); - return res; - } - CC_INLINE Sampler *createSampler(const SamplerInfo &info) { - Sampler *res = createSampler(); - res->initialize(info); - return res; - } - CC_INLINE Shader *createShader(const ShaderInfo &info) { - Shader *res = createShader(); - res->initialize(info); - return res; - } - CC_INLINE InputAssembler *createInputAssembler(const InputAssemblerInfo &info) { - InputAssembler *res = createInputAssembler(); - res->initialize(info); - return res; - } - CC_INLINE RenderPass *createRenderPass(const RenderPassInfo &info) { - RenderPass *res = createRenderPass(); - res->initialize(info); - return res; - } - CC_INLINE Framebuffer *createFramebuffer(const FramebufferInfo &info) { - Framebuffer *res = createFramebuffer(); - res->initialize(info); - return res; - } - CC_INLINE DescriptorSet *createDescriptorSet(const DescriptorSetInfo &info) { - DescriptorSet *res = createDescriptorSet(); - res->initialize(info); - return res; - } - CC_INLINE DescriptorSetLayout *createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) { - DescriptorSetLayout *res = createDescriptorSetLayout(); - res->initialize(info); - return res; - } - CC_INLINE PipelineLayout *createPipelineLayout(const PipelineLayoutInfo &info) { - PipelineLayout *res = createPipelineLayout(); - res->initialize(info); - return res; - } - CC_INLINE PipelineState *createPipelineState(const PipelineStateInfo &info) { - PipelineState *res = createPipelineState(); - res->initialize(info); - return res; - } - CC_INLINE GlobalBarrier *createGlobalBarrier(const GlobalBarrierInfo &info) { - GlobalBarrier *res = createGlobalBarrier(); - res->initialize(info); - return res; - } - CC_INLINE TextureBarrier *createTextureBarrier(const TextureBarrierInfo &info) { - TextureBarrier *res = createTextureBarrier(); - res->initialize(info); - return res; - } - CC_INLINE void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) { - copyBuffersToTexture(buffers.data(), dst, regions.data(), static_cast(regions.size())); - } + inline CommandBuffer * createCommandBuffer(const CommandBufferInfo &info); + inline Queue * createQueue(const QueueInfo &info); + inline Buffer * createBuffer(const BufferInfo &info); + inline Buffer * createBuffer(const BufferViewInfo &info); + inline Texture * createTexture(const TextureInfo &info); + inline Texture * createTexture(const TextureViewInfo &info); + inline Sampler * createSampler(const SamplerInfo &info); + inline Shader * createShader(const ShaderInfo &info); + inline InputAssembler * createInputAssembler(const InputAssemblerInfo &info); + inline RenderPass * createRenderPass(const RenderPassInfo &info); + inline Framebuffer * createFramebuffer(const FramebufferInfo &info); + inline DescriptorSet * createDescriptorSet(const DescriptorSetInfo &info); + inline DescriptorSetLayout *createDescriptorSetLayout(const DescriptorSetLayoutInfo &info); + inline PipelineLayout * createPipelineLayout(const PipelineLayoutInfo &info); + inline PipelineState * createPipelineState(const PipelineStateInfo &info); + inline GlobalBarrier * createGlobalBarrier(const GlobalBarrierInfo &info); + inline TextureBarrier * createTextureBarrier(const TextureBarrierInfo &info); - CC_INLINE void flushCommands(const vector &cmdBuffs) { flushCommands(cmdBuffs.data(), static_cast(cmdBuffs.size())); } + inline void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions); + inline void flushCommands(const vector &cmdBuffs); + inline void flushCommandsForJS(const vector &cmdBuffs); - CC_INLINE void flushCommandsForJS(const vector &cmdBuffs) { flushCommands(cmdBuffs.data(), static_cast(cmdBuffs.size())); } + inline Queue * getQueue() const { return _queue; } + inline CommandBuffer * getCommandBuffer() const { return _cmdBuff; } + inline const DeviceCaps &getCapabilities() const { return _caps; } + inline API getGfxAPI() const { return _API; } + 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)]; } - CC_INLINE Context *getContext() const { return _context; } - CC_INLINE Queue *getQueue() const { return _queue; } - CC_INLINE CommandBuffer *getCommandBuffer() const { return _cmdBuff; } - CC_INLINE const DeviceCaps &getCapabilities() const { return _caps; } - CC_INLINE bool hasFeature(Feature feature) const { return _features[static_cast(feature)]; } - CC_INLINE const BindingMappingInfo &bindingMappingInfo() const { return _bindingMappingInfo; } + inline const BindingMappingInfo &bindingMappingInfo() const { return _bindingMappingInfo; } - CC_INLINE API getGfxAPI() const { return _API; } - CC_INLINE const String &getDeviceName() const { return _deviceName; } - CC_INLINE const String &getRenderer() const { return _renderer; } - CC_INLINE const String &getVendor() const { return _vendor; } - Format getColorFormat() const; - Format getDepthStencilFormat() const; + Format getColorFormat() const; + Format getDepthStencilFormat() const; protected: - friend class DeviceAgent; + static Device *_instance; - virtual CommandBuffer * doCreateCommandBuffer(const CommandBufferInfo &info, bool hasAgent) = 0; + friend class DeviceAgent; + friend class DeviceCreator; + + Device(); + + virtual bool doInit(const DeviceInfo &info) = 0; + virtual void doDestroy() = 0; + + virtual CommandBuffer * createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) = 0; virtual Queue * createQueue() = 0; virtual Buffer * createBuffer() = 0; virtual Texture * createTexture() = 0; @@ -199,9 +135,16 @@ protected: virtual TextureBarrier * createTextureBarrier() = 0; virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) = 0; + // On minimize + virtual void releaseSurface(uintptr_t windowHandle) {} + // On restore + virtual void acquireSurface(uintptr_t windowHandle) {} + virtual void bindRenderContext(bool bound) {} virtual void bindDeviceContext(bool bound) {} + inline Context *getContext() const { return _context; } + API _API = API::UNKNOWN; SurfaceTransform _transform = SurfaceTransform::IDENTITY; String _deviceName; @@ -223,12 +166,123 @@ protected: uint _numTriangles = 0u; BindingMappingInfo _bindingMappingInfo; DeviceCaps _caps; - -private: - static Device *_instance; }; +////////////////////////////////////////////////////////////////////////// + +CommandBuffer *Device::createCommandBuffer(const CommandBufferInfo &info) { + CommandBuffer *res = createCommandBuffer(info, false); + res->initialize(info); + return res; +} + +Queue *Device::createQueue(const QueueInfo &info) { + Queue *res = createQueue(); + res->initialize(info); + return res; +} + +Buffer *Device::createBuffer(const BufferInfo &info) { + Buffer *res = createBuffer(); + res->initialize(info); + return res; +} + +Buffer *Device::createBuffer(const BufferViewInfo &info) { + Buffer *res = createBuffer(); + res->initialize(info); + return res; +} + +Texture *Device::createTexture(const TextureInfo &info) { + Texture *res = createTexture(); + res->initialize(info); + return res; +} + +Texture *Device::createTexture(const TextureViewInfo &info) { + Texture *res = createTexture(); + res->initialize(info); + return res; +} + +Sampler *Device::createSampler(const SamplerInfo &info) { + Sampler *res = createSampler(); + res->initialize(info); + return res; +} + +Shader *Device::createShader(const ShaderInfo &info) { + Shader *res = createShader(); + res->initialize(info); + return res; +} + +InputAssembler *Device::createInputAssembler(const InputAssemblerInfo &info) { + InputAssembler *res = createInputAssembler(); + res->initialize(info); + return res; +} + +RenderPass *Device::createRenderPass(const RenderPassInfo &info) { + RenderPass *res = createRenderPass(); + res->initialize(info); + return res; +} + +Framebuffer *Device::createFramebuffer(const FramebufferInfo &info) { + Framebuffer *res = createFramebuffer(); + res->initialize(info); + return res; +} + +DescriptorSet *Device::createDescriptorSet(const DescriptorSetInfo &info) { + DescriptorSet *res = createDescriptorSet(); + res->initialize(info); + return res; +} + +DescriptorSetLayout *Device::createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) { + DescriptorSetLayout *res = createDescriptorSetLayout(); + res->initialize(info); + return res; +} + +PipelineLayout *Device::createPipelineLayout(const PipelineLayoutInfo &info) { + PipelineLayout *res = createPipelineLayout(); + res->initialize(info); + return res; +} + +PipelineState *Device::createPipelineState(const PipelineStateInfo &info) { + PipelineState *res = createPipelineState(); + res->initialize(info); + return res; +} + +GlobalBarrier *Device::createGlobalBarrier(const GlobalBarrierInfo &info) { + GlobalBarrier *res = createGlobalBarrier(); + res->initialize(info); + return res; +} + +TextureBarrier *Device::createTextureBarrier(const TextureBarrierInfo &info) { + TextureBarrier *res = createTextureBarrier(); + res->initialize(info); + return res; +} + +void Device::copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList ®ions) { + copyBuffersToTexture(buffers.data(), dst, regions.data(), static_cast(regions.size())); +} + +void Device::flushCommands(const vector &cmdBuffs) { + flushCommands(cmdBuffs.data(), static_cast(cmdBuffs.size())); +} + +void Device::flushCommandsForJS(const vector &cmdBuffs) { + flushCommands(cmdBuffs.data(), static_cast(cmdBuffs.size())); +} + } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_DEVICE_H_ diff --git a/native/cocos/renderer/gfx-base/GFXFramebuffer.cpp b/native/cocos/renderer/gfx-base/GFXFramebuffer.cpp index c173035bed..749e611cd5 100644 --- a/native/cocos/renderer/gfx-base/GFXFramebuffer.cpp +++ b/native/cocos/renderer/gfx-base/GFXFramebuffer.cpp @@ -31,15 +31,14 @@ namespace cc { namespace gfx { -Framebuffer::Framebuffer(Device *device) -: GFXObject(ObjectType::FRAMEBUFFER), - _device(device) { +Framebuffer::Framebuffer() +: GFXObject(ObjectType::FRAMEBUFFER) { } Framebuffer::~Framebuffer() { } -uint Framebuffer::computeHash(const FramebufferInfo& info) { +uint Framebuffer::computeHash(const FramebufferInfo &info) { uint seed = info.colorTextures.size() + info.colorMipmapLevels.size() + 2; for (const Texture *attachment : info.colorTextures) { seed ^= (uint)attachment->getTextureID() + 0x9e3779b9 + (seed << 6) + (seed >> 2); @@ -52,5 +51,21 @@ uint Framebuffer::computeHash(const FramebufferInfo& info) { return seed; } +void Framebuffer::initialize(const FramebufferInfo &info) { + _renderPass = info.renderPass; + _colorTextures = info.colorTextures; + _depthStencilTexture = info.depthStencilTexture; + + doInit(info); +} + +void Framebuffer::destroy() { + doDestroy(); + + _renderPass = nullptr; + _colorTextures.clear(); + _depthStencilTexture = nullptr; +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXFramebuffer.h b/native/cocos/renderer/gfx-base/GFXFramebuffer.h index ebc3b242be..c7aff3ef67 100644 --- a/native/cocos/renderer/gfx-base/GFXFramebuffer.h +++ b/native/cocos/renderer/gfx-base/GFXFramebuffer.h @@ -32,21 +32,22 @@ namespace gfx { class CC_DLL Framebuffer : public GFXObject { public: - Framebuffer(Device *device); + Framebuffer(); virtual ~Framebuffer(); static uint computeHash(const FramebufferInfo &info); - virtual bool initialize(const FramebufferInfo &info) = 0; - virtual void destroy() = 0; + void initialize(const FramebufferInfo &info); + void destroy(); - CC_INLINE Device *getDevice() const { return _device; } CC_INLINE RenderPass *getRenderPass() const { return _renderPass; } CC_INLINE const TextureList &getColorTextures() const { return _colorTextures; } CC_INLINE Texture *getDepthStencilTexture() const { return _depthStencilTexture; } protected: - Device * _device = nullptr; + virtual void doInit(const FramebufferInfo &info) = 0; + virtual void doDestroy() = 0; + RenderPass *_renderPass = nullptr; TextureList _colorTextures; Texture * _depthStencilTexture = nullptr; diff --git a/native/cocos/renderer/gfx-base/GFXGlobalBarrier.cpp b/native/cocos/renderer/gfx-base/GFXGlobalBarrier.cpp index 986c21ed4b..0ef1059f11 100644 --- a/native/cocos/renderer/gfx-base/GFXGlobalBarrier.cpp +++ b/native/cocos/renderer/gfx-base/GFXGlobalBarrier.cpp @@ -31,9 +31,8 @@ namespace cc { namespace gfx { -GlobalBarrier::GlobalBarrier(Device *device) -: GFXObject(ObjectType::GLOBAL_BARRIER), - _device(device) { +GlobalBarrier::GlobalBarrier() +: GFXObject(ObjectType::GLOBAL_BARRIER) { } GlobalBarrier::~GlobalBarrier() { diff --git a/native/cocos/renderer/gfx-base/GFXGlobalBarrier.h b/native/cocos/renderer/gfx-base/GFXGlobalBarrier.h index aef7af4168..655500b354 100644 --- a/native/cocos/renderer/gfx-base/GFXGlobalBarrier.h +++ b/native/cocos/renderer/gfx-base/GFXGlobalBarrier.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_GLOBAL_BARRIER_H_ -#define CC_CORE_GFX_GLOBAL_BARRIER_H_ +#pragma once #include "GFXObject.h" @@ -33,7 +32,7 @@ namespace gfx { class CC_DLL GlobalBarrier : public GFXObject { public: - GlobalBarrier(Device *device); + GlobalBarrier(); virtual ~GlobalBarrier(); static uint computeHash(const GlobalBarrierInfo &info); @@ -43,13 +42,12 @@ public: protected: friend class Device; - virtual bool initialize(const GlobalBarrierInfo &info) { _info = info; return true; } + virtual void doInit(const GlobalBarrierInfo &info) {} + + void initialize(const GlobalBarrierInfo &info) { _info = info; doInit(info); } - Device *_device = nullptr; GlobalBarrierInfo _info; }; } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_GLOBAL_BARRIER_H_ diff --git a/native/cocos/renderer/gfx-base/GFXInputAssembler.cpp b/native/cocos/renderer/gfx-base/GFXInputAssembler.cpp index c83b27995d..f78a4ee58a 100644 --- a/native/cocos/renderer/gfx-base/GFXInputAssembler.cpp +++ b/native/cocos/renderer/gfx-base/GFXInputAssembler.cpp @@ -25,25 +25,26 @@ #include "base/CoreStd.h" -#include "GFXObject.h" +#include "GFXBuffer.h" #include "GFXInputAssembler.h" +#include "GFXObject.h" namespace cc { namespace gfx { -InputAssembler::InputAssembler(Device *device) -: GFXObject(ObjectType::INPUT_ASSEMBLER), _device(device) { +InputAssembler::InputAssembler() +: GFXObject(ObjectType::INPUT_ASSEMBLER) { } InputAssembler::~InputAssembler() { } void InputAssembler::extractDrawInfo(DrawInfo &drawInfo) const { - drawInfo.vertexCount = _vertexCount; - drawInfo.firstVertex = _firstVertex; - drawInfo.indexCount = _indexCount; - drawInfo.firstIndex = _firstIndex; - drawInfo.vertexOffset = _vertexOffset; + drawInfo.vertexCount = _vertexCount; + drawInfo.firstVertex = _firstVertex; + drawInfo.indexCount = _indexCount; + drawInfo.firstIndex = _firstIndex; + drawInfo.vertexOffset = _vertexOffset; drawInfo.instanceCount = _instanceCount; drawInfo.firstInstance = _firstInstance; } @@ -63,5 +64,32 @@ uint InputAssembler::computeAttributesHash() const { return static_cast(seed); } +void InputAssembler::initialize(const InputAssemblerInfo &info) { + _attributes = info.attributes; + _vertexBuffers = info.vertexBuffers; + _indexBuffer = info.indexBuffer; + _indirectBuffer = info.indirectBuffer; + + if (_indexBuffer) { + _indexCount = _indexBuffer->getCount(); + _firstIndex = 0; + } else if (_vertexBuffers.size()) { + _vertexCount = _vertexBuffers[0]->getCount(); + _firstVertex = 0; + _vertexOffset = 0; + } + _attributesHash = computeAttributesHash(); + + doInit(info); +} + +void InputAssembler::destroy() { + _attributes.clear(); + _vertexBuffers.clear(); + _indexBuffer = nullptr; + _indirectBuffer = nullptr; + _indexCount = _firstIndex = _vertexCount = _firstVertex = _vertexOffset = _attributesHash = 0u; +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXInputAssembler.h b/native/cocos/renderer/gfx-base/GFXInputAssembler.h index bfba8e9146..2c6f7968e4 100644 --- a/native/cocos/renderer/gfx-base/GFXInputAssembler.h +++ b/native/cocos/renderer/gfx-base/GFXInputAssembler.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_INPUT_ASSEMBLER_H_ -#define CC_CORE_GFX_INPUT_ASSEMBLER_H_ +#pragma once #include "GFXObject.h" @@ -33,28 +32,26 @@ namespace gfx { class CC_DLL InputAssembler : public GFXObject { public: - InputAssembler(Device *device); + InputAssembler(); virtual ~InputAssembler(); -public: - virtual bool initialize(const InputAssemblerInfo &info) = 0; - virtual void destroy() = 0; + void initialize(const InputAssemblerInfo &info); + void destroy(); void extractDrawInfo(DrawInfo &drawInfo) const; - CC_INLINE Device *getDevice() const { return _device; } CC_INLINE const AttributeList &getAttributes() const { return _attributes; } CC_INLINE const BufferList &getVertexBuffers() const { return _vertexBuffers; } CC_INLINE Buffer *getIndexBuffer() const { return _indexBuffer; } CC_INLINE Buffer *getIndirectBuffer() const { return _indirectBuffer; } - CC_INLINE uint getVertexCount() const { return _vertexCount; } - CC_INLINE uint getFirstVertex() const { return _firstVertex; } - CC_INLINE uint getIndexCount() const { return _indexCount; } - CC_INLINE uint getFirstIndex() const { return _firstIndex; } - CC_INLINE uint getVertexOffset() const { return _vertexOffset; } - CC_INLINE uint getInstanceCount() const { return _instanceCount; } - CC_INLINE uint getFirstInstance() const { return _firstInstance; } - CC_INLINE uint getAttributesHash() const { return _attributesHash; } + CC_INLINE uint getVertexCount() const { return _vertexCount; } + CC_INLINE uint getFirstVertex() const { return _firstVertex; } + CC_INLINE uint getIndexCount() const { return _indexCount; } + CC_INLINE uint getFirstIndex() const { return _firstIndex; } + CC_INLINE uint getVertexOffset() const { return _vertexOffset; } + CC_INLINE uint getInstanceCount() const { return _instanceCount; } + CC_INLINE uint getFirstInstance() const { return _firstInstance; } + CC_INLINE uint getAttributesHash() const { return _attributesHash; } virtual void setVertexCount(uint count) { _vertexCount = count; } virtual void setFirstVertex(uint first) { _firstVertex = first; } @@ -65,24 +62,24 @@ public: virtual void setFirstInstance(uint first) { _firstInstance = first; } protected: + virtual void doInit(const InputAssemblerInfo &info) = 0; + virtual void doDestroy() = 0; + uint computeAttributesHash() const; - Device *_device = nullptr; AttributeList _attributes; - BufferList _vertexBuffers; - Buffer *_indexBuffer = nullptr; - Buffer *_indirectBuffer = nullptr; - uint _vertexCount = 0; - uint _firstVertex = 0; - uint _indexCount = 0; - uint _firstIndex = 0; - uint _vertexOffset = 0; - uint _instanceCount = 0; - uint _firstInstance = 0; - uint _attributesHash = 0; + BufferList _vertexBuffers; + Buffer * _indexBuffer = nullptr; + Buffer * _indirectBuffer = nullptr; + uint _vertexCount = 0; + uint _firstVertex = 0; + uint _indexCount = 0; + uint _firstIndex = 0; + uint _vertexOffset = 0; + uint _instanceCount = 0; + uint _firstInstance = 0; + uint _attributesHash = 0; }; } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_INPUT_ASSEMBLER_H_ diff --git a/native/cocos/renderer/gfx-base/GFXPipelineLayout.cpp b/native/cocos/renderer/gfx-base/GFXPipelineLayout.cpp index 7f2af5ddb9..fd077ecccb 100644 --- a/native/cocos/renderer/gfx-base/GFXPipelineLayout.cpp +++ b/native/cocos/renderer/gfx-base/GFXPipelineLayout.cpp @@ -31,13 +31,24 @@ namespace cc { namespace gfx { -PipelineLayout::PipelineLayout(Device *device) -: GFXObject(ObjectType::PIPELINE_LAYOUT), - _device(device) { +PipelineLayout::PipelineLayout() +: GFXObject(ObjectType::PIPELINE_LAYOUT) { } PipelineLayout::~PipelineLayout() { } +void PipelineLayout::initialize(const PipelineLayoutInfo& info) { + _setLayouts = info.setLayouts; + + doInit(info); +} + +void PipelineLayout::destroy() { + doDestroy(); + + _setLayouts.clear(); +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXPipelineLayout.h b/native/cocos/renderer/gfx-base/GFXPipelineLayout.h index 8a3f74b6d5..dc34bf3ae0 100644 --- a/native/cocos/renderer/gfx-base/GFXPipelineLayout.h +++ b/native/cocos/renderer/gfx-base/GFXPipelineLayout.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_PIPELINE_LAYOUT_H_ -#define CC_CORE_GFX_PIPELINE_LAYOUT_H_ +#pragma once #include "GFXObject.h" @@ -33,22 +32,20 @@ namespace gfx { class CC_DLL PipelineLayout : public GFXObject { public: - PipelineLayout(Device *device); + PipelineLayout(); virtual ~PipelineLayout(); -public: - virtual bool initialize(const PipelineLayoutInfo &info) = 0; - virtual void destroy() = 0; + void initialize(const PipelineLayoutInfo &info); + void destroy(); - CC_INLINE Device *getDevice() const { return _device; } CC_INLINE const DescriptorSetLayoutList &getSetLayouts() const { return _setLayouts; } protected: - Device *_device = nullptr; + virtual void doInit(const PipelineLayoutInfo &info) = 0; + virtual void doDestroy() = 0; + DescriptorSetLayoutList _setLayouts; }; } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_PIPELINE_LAYOUT_H_ diff --git a/native/cocos/renderer/gfx-base/GFXPipelineState.cpp b/native/cocos/renderer/gfx-base/GFXPipelineState.cpp index 7d58e89977..d751e6ebb9 100644 --- a/native/cocos/renderer/gfx-base/GFXPipelineState.cpp +++ b/native/cocos/renderer/gfx-base/GFXPipelineState.cpp @@ -31,12 +31,35 @@ namespace cc { namespace gfx { -PipelineState::PipelineState(Device *device) -: GFXObject(ObjectType::PIPELINE_STATE), _device(device) { +PipelineState::PipelineState() +: GFXObject(ObjectType::PIPELINE_STATE) { } PipelineState::~PipelineState() { } +void PipelineState::initialize(const PipelineStateInfo &info) { + _primitive = info.primitive; + _shader = info.shader; + _inputState = info.inputState; + _rasterizerState = info.rasterizerState; + _depthStencilState = info.depthStencilState; + _bindPoint = info.bindPoint; + _blendState = info.blendState; + _dynamicStates = info.dynamicStates; + _renderPass = info.renderPass; + _pipelineLayout = info.pipelineLayout; + + doInit(info); +} + +void PipelineState::destroy() { + doDestroy(); + + _shader = nullptr; + _renderPass = nullptr; + _pipelineLayout = nullptr; +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXPipelineState.h b/native/cocos/renderer/gfx-base/GFXPipelineState.h index b00d4d791e..89b6d804f2 100644 --- a/native/cocos/renderer/gfx-base/GFXPipelineState.h +++ b/native/cocos/renderer/gfx-base/GFXPipelineState.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_PIPELINE_STATE_H_ -#define CC_CORE_GFX_PIPELINE_STATE_H_ +#pragma once #include "GFXObject.h" @@ -33,17 +32,15 @@ namespace gfx { class CC_DLL PipelineState : public GFXObject { public: - PipelineState(Device *device); + PipelineState(); virtual ~PipelineState(); -public: - virtual bool initialize(const PipelineStateInfo &info) = 0; - virtual void destroy() = 0; + void initialize(const PipelineStateInfo &info); + void destroy(); - CC_INLINE Device *getDevice() const { return _device; } - CC_INLINE Shader *getShader() const { return _shader; } + CC_INLINE Shader * getShader() const { return _shader; } CC_INLINE PipelineBindPoint getBindPoint() const { return _bindPoint; } - CC_INLINE PrimitiveMode getPrimitive() const { return _primitive; } + CC_INLINE PrimitiveMode getPrimitive() const { return _primitive; } CC_INLINE DynamicStateFlags getDynamicStates() const { return _dynamicStates; } CC_INLINE const InputState &getInputState() const { return _inputState; } CC_INLINE const RasterizerState &getRasterizerState() const { return _rasterizerState; } @@ -53,20 +50,20 @@ public: CC_INLINE const PipelineLayout *getPipelineLayout() const { return _pipelineLayout; } protected: - Device *_device = nullptr; - Shader *_shader = nullptr; - PipelineBindPoint _bindPoint = PipelineBindPoint::GRAPHICS; - PrimitiveMode _primitive = PrimitiveMode::TRIANGLE_LIST; + virtual void doInit(const PipelineStateInfo &info) = 0; + virtual void doDestroy() = 0; + + Shader * _shader = nullptr; + PipelineBindPoint _bindPoint = PipelineBindPoint::GRAPHICS; + PrimitiveMode _primitive = PrimitiveMode::TRIANGLE_LIST; DynamicStateFlags _dynamicStates = DynamicStateFlags::NONE; - InputState _inputState; - RasterizerState _rasterizerState; + InputState _inputState; + RasterizerState _rasterizerState; DepthStencilState _depthStencilState; - BlendState _blendState; - RenderPass *_renderPass = nullptr; - PipelineLayout *_pipelineLayout = nullptr; + BlendState _blendState; + RenderPass * _renderPass = nullptr; + PipelineLayout * _pipelineLayout = nullptr; }; } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_PIPELINE_STATE_H_ diff --git a/native/cocos/renderer/gfx-base/GFXQueue.cpp b/native/cocos/renderer/gfx-base/GFXQueue.cpp index f23e09c162..fb5f36e403 100644 --- a/native/cocos/renderer/gfx-base/GFXQueue.cpp +++ b/native/cocos/renderer/gfx-base/GFXQueue.cpp @@ -31,13 +31,24 @@ namespace cc { namespace gfx { -Queue::Queue(Device *device) -: GFXObject(ObjectType::QUEUE), - _device(device) { +Queue::Queue() +: GFXObject(ObjectType::QUEUE) { } Queue::~Queue() { } +void Queue::initialize(const QueueInfo& info) { + _type = info.type; + + doInit(info); +} + +void Queue::destroy() { + doDestroy(); + + _type = QueueType::GRAPHICS; +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXQueue.h b/native/cocos/renderer/gfx-base/GFXQueue.h index 8feeb1b12f..da8eb1c164 100644 --- a/native/cocos/renderer/gfx-base/GFXQueue.h +++ b/native/cocos/renderer/gfx-base/GFXQueue.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_QUEUE_H_ -#define CC_CORE_GFX_QUEUE_H_ +#pragma once #include "GFXObject.h" @@ -33,26 +32,26 @@ namespace gfx { class CC_DLL Queue : public GFXObject { public: - Queue(Device *device); + Queue(); virtual ~Queue(); -public: - virtual bool initialize(const QueueInfo &info) = 0; - virtual void destroy() = 0; + void initialize(const QueueInfo &info); + void destroy(); + virtual void submit(CommandBuffer *const *cmdBuffs, uint count) = 0; CC_INLINE void submit(const CommandBufferList &cmdBuffs) { submit(cmdBuffs.data(), static_cast(cmdBuffs.size())); } - CC_INLINE Device *getDevice() const { return _device; } - CC_INLINE QueueType getType() const { return _type; } CC_INLINE void submitForJS(const CommandBufferList &cmdBuffs) { submit(cmdBuffs.data(), static_cast(cmdBuffs.size())); } + CC_INLINE QueueType getType() const { return _type; } + protected: - Device *_device = nullptr; - QueueType _type = QueueType::GRAPHICS; + virtual void doInit(const QueueInfo &info) = 0; + virtual void doDestroy() = 0; + + QueueType _type = QueueType::GRAPHICS; }; } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_QUEUE_H_ diff --git a/native/cocos/renderer/gfx-base/GFXRenderPass.cpp b/native/cocos/renderer/gfx-base/GFXRenderPass.cpp index 7f6a48b443..035a5f0b09 100644 --- a/native/cocos/renderer/gfx-base/GFXRenderPass.cpp +++ b/native/cocos/renderer/gfx-base/GFXRenderPass.cpp @@ -31,8 +31,8 @@ namespace cc { namespace gfx { -RenderPass::RenderPass(Device *device) -: GFXObject(ObjectType::RENDER_PASS), _device(device) { +RenderPass::RenderPass() +: GFXObject(ObjectType::RENDER_PASS) { } RenderPass::~RenderPass() { @@ -196,5 +196,22 @@ uint RenderPass::computeHash(const RenderPassInfo &info) { return seed; } +void RenderPass::initialize(const RenderPassInfo &info) { + _colorAttachments = info.colorAttachments; + _depthStencilAttachment = info.depthStencilAttachment; + _subpasses = info.subpasses; + _hash = computeHash(); + + doInit(info); +} + +void RenderPass::destroy() { + doDestroy(); + + _colorAttachments.clear(); + _subpasses.clear(); + _hash = 0u; +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXRenderPass.h b/native/cocos/renderer/gfx-base/GFXRenderPass.h index 0a0435ce3e..93271c5fcf 100644 --- a/native/cocos/renderer/gfx-base/GFXRenderPass.h +++ b/native/cocos/renderer/gfx-base/GFXRenderPass.h @@ -32,15 +32,14 @@ namespace gfx { class CC_DLL RenderPass : public GFXObject { public: - RenderPass(Device *device); + RenderPass(); virtual ~RenderPass(); static uint computeHash(const RenderPassInfo &info); - virtual bool initialize(const RenderPassInfo &info) = 0; - virtual void destroy() = 0; + void initialize(const RenderPassInfo &info); + void destroy(); - CC_INLINE Device *getDevice() const { return _device; } CC_INLINE const ColorAttachmentList &getColorAttachments() const { return _colorAttachments; } CC_INLINE const DepthStencilAttachment &getDepthStencilAttachment() const { return _depthStencilAttachment; } CC_INLINE const SubpassInfoList &getSubpasses() const { return _subpasses; } @@ -49,7 +48,9 @@ public: protected: uint computeHash(); - Device * _device = nullptr; + virtual void doInit(const RenderPassInfo &info) = 0; + virtual void doDestroy() = 0; + ColorAttachmentList _colorAttachments; DepthStencilAttachment _depthStencilAttachment; SubpassInfoList _subpasses; diff --git a/native/cocos/renderer/gfx-base/GFXSampler.cpp b/native/cocos/renderer/gfx-base/GFXSampler.cpp index ca078ef5a5..3de43697a9 100644 --- a/native/cocos/renderer/gfx-base/GFXSampler.cpp +++ b/native/cocos/renderer/gfx-base/GFXSampler.cpp @@ -31,8 +31,8 @@ namespace cc { namespace gfx { -Sampler::Sampler(Device *device) -: GFXObject(ObjectType::SAMPLER), _device(device) { +Sampler::Sampler() +: GFXObject(ObjectType::SAMPLER) { _borderColor.x = 0.0f; _borderColor.y = 0.0f; _borderColor.z = 0.0f; @@ -42,5 +42,24 @@ Sampler::Sampler(Device *device) Sampler::~Sampler() { } +void Sampler::initialize(const SamplerInfo &info) { + _minFilter = info.minFilter; + _magFilter = info.magFilter; + _mipFilter = info.mipFilter; + _addressU = info.addressU; + _addressV = info.addressV; + _addressW = info.addressW; + _maxAnisotropy = info.maxAnisotropy; + _cmpFunc = info.cmpFunc; + _borderColor = info.borderColor; + _mipLODBias = info.mipLODBias; + + doInit(info); +} + +void Sampler::destroy() { + doDestroy(); +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXSampler.h b/native/cocos/renderer/gfx-base/GFXSampler.h index 2019ee5f31..e0a2545290 100644 --- a/native/cocos/renderer/gfx-base/GFXSampler.h +++ b/native/cocos/renderer/gfx-base/GFXSampler.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_SAMPLER_H_ -#define CC_CORE_GFX_SAMPLER_H_ +#pragma once #include "GFXObject.h" @@ -33,39 +32,38 @@ namespace gfx { class CC_DLL Sampler : public GFXObject { public: - Sampler(Device *device); + Sampler(); virtual ~Sampler(); - virtual bool initialize(const SamplerInfo &info) = 0; - virtual void destroy() = 0; + void initialize(const SamplerInfo &info); + void destroy(); - CC_INLINE Device *getDevice() const { return _device; } - CC_INLINE Filter getMinFilter() const { return _minFilter; } - CC_INLINE Filter getMagFilter() const { return _magFilter; } - CC_INLINE Filter getMipFilter() const { return _mipFilter; } - CC_INLINE Address getAddressU() const { return _addressU; } - CC_INLINE Address getAddressV() const { return _addressV; } - CC_INLINE Address getAddressW() const { return _addressW; } - CC_INLINE uint getMaxAnisotropy() const { return _maxAnisotropy; } + CC_INLINE Filter getMinFilter() const { return _minFilter; } + CC_INLINE Filter getMagFilter() const { return _magFilter; } + CC_INLINE Filter getMipFilter() const { return _mipFilter; } + CC_INLINE Address getAddressU() const { return _addressU; } + CC_INLINE Address getAddressV() const { return _addressV; } + CC_INLINE Address getAddressW() const { return _addressW; } + CC_INLINE uint getMaxAnisotropy() const { return _maxAnisotropy; } CC_INLINE ComparisonFunc getCmpFunc() const { return _cmpFunc; } CC_INLINE const Color &getBorderColor() const { return _borderColor; } - CC_INLINE float getMipLODBias() const { return _mipLODBias; } + CC_INLINE float getMipLODBias() const { return _mipLODBias; } protected: - Device *_device = nullptr; - Filter _minFilter = Filter::NONE; - Filter _magFilter = Filter::NONE; - Filter _mipFilter = Filter::NONE; - Address _addressU = Address::WRAP; - Address _addressV = Address::WRAP; - Address _addressW = Address::WRAP; - uint _maxAnisotropy = 0; - ComparisonFunc _cmpFunc = ComparisonFunc::ALWAYS; - Color _borderColor; - float _mipLODBias = 0.0f; + virtual void doInit(const SamplerInfo &info) = 0; + virtual void doDestroy() = 0; + + Filter _minFilter = Filter::NONE; + Filter _magFilter = Filter::NONE; + Filter _mipFilter = Filter::NONE; + Address _addressU = Address::WRAP; + Address _addressV = Address::WRAP; + Address _addressW = Address::WRAP; + uint _maxAnisotropy = 0; + ComparisonFunc _cmpFunc = ComparisonFunc::ALWAYS; + Color _borderColor; + float _mipLODBias = 0.0f; }; } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_SAMPLER_H_ diff --git a/native/cocos/renderer/gfx-base/GFXShader.cpp b/native/cocos/renderer/gfx-base/GFXShader.cpp index 7454f79a95..dd6f90e161 100644 --- a/native/cocos/renderer/gfx-base/GFXShader.cpp +++ b/native/cocos/renderer/gfx-base/GFXShader.cpp @@ -32,14 +32,42 @@ namespace cc { namespace gfx { -Shader::Shader(Device *device) -: GFXObject(ObjectType::SHADER), - _device(device) { +Shader::Shader() +: GFXObject(ObjectType::SHADER) { _shaderID = generateShaderID(); } Shader::~Shader() { } +void Shader::initialize(const ShaderInfo &info) { + _name = info.name; + _stages = info.stages; + _attributes = info.attributes; + _blocks = info.blocks; + _buffers = info.buffers; + _samplerTextures = info.samplerTextures; + _samplers = info.samplers; + _textures = info.textures; + _images = info.images; + _subpassInputs = info.subpassInputs; + + doInit(info); +} + +void Shader::destroy() { + doDestroy(); + + _stages.clear(); + _attributes.clear(); + _blocks.clear(); + _buffers.clear(); + _samplerTextures.clear(); + _samplers.clear(); + _textures.clear(); + _images.clear(); + _subpassInputs.clear(); +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXShader.h b/native/cocos/renderer/gfx-base/GFXShader.h index 1d424f3922..013ecd6353 100644 --- a/native/cocos/renderer/gfx-base/GFXShader.h +++ b/native/cocos/renderer/gfx-base/GFXShader.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_SHADER_H_ -#define CC_CORE_GFX_SHADER_H_ +#pragma once #include "GFXObject.h" @@ -33,13 +32,12 @@ namespace gfx { class CC_DLL Shader : public GFXObject { public: - Shader(Device *device); + Shader(); virtual ~Shader(); - virtual bool initialize(const ShaderInfo &info) = 0; - virtual void destroy() = 0; + void initialize(const ShaderInfo &info); + void destroy(); - CC_INLINE Device *getDevice() const { return _device; } CC_INLINE uint getID() const { return _shaderID; } CC_INLINE const String &getName() const { return _name; } CC_INLINE const ShaderStageList &getStages() const { return _stages; } @@ -58,7 +56,9 @@ protected: return _idGen++; } - Device * _device = nullptr; + virtual void doInit(const ShaderInfo &info) = 0; + virtual void doDestroy() = 0; + uint _shaderID = 0; String _name; ShaderStageList _stages; @@ -74,5 +74,3 @@ protected: } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_SHADER_H_ diff --git a/native/cocos/renderer/gfx-base/GFXTexture.cpp b/native/cocos/renderer/gfx-base/GFXTexture.cpp index 162bdeda3e..0d3663dc2f 100644 --- a/native/cocos/renderer/gfx-base/GFXTexture.cpp +++ b/native/cocos/renderer/gfx-base/GFXTexture.cpp @@ -25,15 +25,15 @@ #include "base/CoreStd.h" +#include "GFXDevice.h" #include "GFXObject.h" #include "GFXTexture.h" namespace cc { namespace gfx { -Texture::Texture(Device *device) -: GFXObject(ObjectType::TEXTURE), - _device(device) { +Texture::Texture() +: GFXObject(ObjectType::TEXTURE) { _textureID = generateTextureID(); } @@ -55,5 +55,102 @@ uint Texture::computeHash(const TextureInfo &info) { return seed; } +void Texture::initialize(const TextureInfo &info) { + _type = info.type; + _usage = info.usage; + _format = info.format; + _width = info.width; + _height = info.height; + _depth = info.depth; + _layerCount = info.layerCount; + _levelCount = info.levelCount; + _samples = info.samples; + _flags = info.flags; + _size = FormatSize(_format, _width, _height, _depth); + +//#if CC_DEBUG > 0 +// switch (_format) { // device feature validation +// case Format::D16: +// if (Device::getInstance()->hasFeature(Feature::FORMAT_D16)) break; +// CC_LOG_ERROR("D16 texture format is not supported on this backend"); +// return; +// case Format::D16S8: +// if (Device::getInstance()->hasFeature(Feature::FORMAT_D16S8)) break; +// CC_LOG_ERROR("D16S8 texture format is not supported on this backend"); +// return; +// case Format::D24: +// if (Device::getInstance()->hasFeature(Feature::FORMAT_D24)) break; +// CC_LOG_ERROR("D24 texture format is not supported on this backend"); +// return; +// case Format::D24S8: +// if (Device::getInstance()->hasFeature(Feature::FORMAT_D24S8)) break; +// CC_LOG_ERROR("D24S8 texture format is not supported on this backend"); +// return; +// case Format::D32F: +// if (Device::getInstance()->hasFeature(Feature::FORMAT_D32F)) break; +// CC_LOG_ERROR("D32F texture format is not supported on this backend"); +// return; +// case Format::D32F_S8: +// if (Device::getInstance()->hasFeature(Feature::FORMAT_D32FS8)) break; +// CC_LOG_ERROR("D32FS8 texture format is not supported on this backend"); +// return; +// case Format::RGB8: +// if (Device::getInstance()->hasFeature(Feature::FORMAT_RGB8)) break; +// CC_LOG_ERROR("RGB8 texture format is not supported on this backend"); +// return; +// default: break; +// } +//#endif + + Device::getInstance()->getMemoryStatus().textureSize += _size; + + doInit(info); +} + +void Texture::initialize(const TextureViewInfo &info) { + _isTextureView = true; + + _type = info.texture->getType(); + _format = info.format; + _baseLayer = info.baseLayer; + _layerCount = info.layerCount; + _baseLevel = info.baseLevel; + _levelCount = info.levelCount; + _usage = info.texture->getUsage(); + _width = info.texture->getWidth(); + _height = info.texture->getHeight(); + _depth = info.texture->getDepth(); + _samples = info.texture->getSamples(); + _flags = info.texture->getFlags(); + _size = FormatSize(_format, _width, _height, _depth); + _isTextureView = true; + + doInit(info); +} + +void Texture::destroy() { + doDestroy(); + + Device::getInstance()->getMemoryStatus().textureSize -= _size; + + _format = Format::UNKNOWN; + _width = _height = _depth = _size = 0; +} + +void Texture::resize(uint width, uint height) { + CCASSERT(!_isTextureView, "Cannot resize texture views"); + + if (_width != width || _height != height) { + doResize(width, height); + + Device::getInstance()->getMemoryStatus().textureSize -= _size; + + _width = width; + _height = height; + _size = FormatSize(_format, width, height, _depth); + Device::getInstance()->getMemoryStatus().textureSize += _size; + } +} + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-base/GFXTexture.h b/native/cocos/renderer/gfx-base/GFXTexture.h index 13f5da54eb..214d86f9d4 100644 --- a/native/cocos/renderer/gfx-base/GFXTexture.h +++ b/native/cocos/renderer/gfx-base/GFXTexture.h @@ -32,17 +32,16 @@ namespace gfx { class CC_DLL Texture : public GFXObject { public: - Texture(Device *device); + Texture(); virtual ~Texture(); static uint computeHash(const TextureInfo &info); - virtual bool initialize(const TextureInfo &info) = 0; - virtual bool initialize(const TextureViewInfo &info) = 0; - virtual void destroy() = 0; - virtual void resize(uint width, uint height) = 0; + void initialize(const TextureInfo &info); + void initialize(const TextureViewInfo &info); + void destroy(); + void resize(uint width, uint height); - CC_INLINE Device * getDevice() const { return _device; } CC_INLINE uint getTextureID() const { return _textureID; } CC_INLINE TextureType getType() const { return _type; } CC_INLINE TextureUsage getUsage() const { return _usage; } @@ -55,7 +54,6 @@ public: CC_INLINE uint getSize() const { return _size; } CC_INLINE SampleCount getSamples() const { return _samples; } CC_INLINE TextureFlags getFlags() const { return _flags; } - CC_INLINE uint8_t *getBuffer() const { return _buffer; } CC_INLINE bool isTextureView() const { return _isTextureView; } protected: @@ -64,7 +62,11 @@ protected: return _idGen++; } - Device * _device = nullptr; + virtual void doInit(const TextureInfo &info) = 0; + virtual void doInit(const TextureViewInfo &info) = 0; + virtual void doDestroy() = 0; + virtual void doResize(uint width, uint height) = 0; + uint _textureID = 0; TextureType _type = TextureType::TEX2D; TextureUsage _usage = TextureUsageBit::NONE; @@ -79,7 +81,6 @@ protected: uint _size = 0u; SampleCount _samples = SampleCount::X1; TextureFlags _flags = TextureFlagBit::NONE; - uint8_t * _buffer = nullptr; bool _isTextureView = false; }; diff --git a/native/cocos/renderer/gfx-base/GFXTextureBarrier.cpp b/native/cocos/renderer/gfx-base/GFXTextureBarrier.cpp index 0900587e03..0030e333f9 100644 --- a/native/cocos/renderer/gfx-base/GFXTextureBarrier.cpp +++ b/native/cocos/renderer/gfx-base/GFXTextureBarrier.cpp @@ -32,9 +32,8 @@ namespace cc { namespace gfx { -TextureBarrier::TextureBarrier(Device *device) -: GFXObject(ObjectType::TEXTURE_BARRIER), - _device(device) { +TextureBarrier::TextureBarrier() +: GFXObject(ObjectType::TEXTURE_BARRIER) { } TextureBarrier::~TextureBarrier() { diff --git a/native/cocos/renderer/gfx-base/GFXTextureBarrier.h b/native/cocos/renderer/gfx-base/GFXTextureBarrier.h index bbeaea276d..17d286546f 100644 --- a/native/cocos/renderer/gfx-base/GFXTextureBarrier.h +++ b/native/cocos/renderer/gfx-base/GFXTextureBarrier.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_CORE_GFX_TEXTURE_BARRIER_H_ -#define CC_CORE_GFX_TEXTURE_BARRIER_H_ +#pragma once #include "GFXObject.h" @@ -33,7 +32,7 @@ namespace gfx { class CC_DLL TextureBarrier : public GFXObject { public: - TextureBarrier(Device *device); + TextureBarrier(); virtual ~TextureBarrier(); static uint computeHash(const TextureBarrierInfo &info); @@ -43,13 +42,12 @@ public: protected: friend class Device; - virtual bool initialize(const TextureBarrierInfo &info) { _info = info; return true; } + virtual void doInit(const TextureBarrierInfo &info) {} + + void initialize(const TextureBarrierInfo &info) { _info = info; doInit(info); } - Device *_device = nullptr; TextureBarrierInfo _info; }; } // namespace gfx } // namespace cc - -#endif // CC_CORE_GFX_GLOBAL_BARRIER_H_ diff --git a/native/cocos/renderer/gfx-empty/EmptyBuffer.cpp b/native/cocos/renderer/gfx-empty/EmptyBuffer.cpp new file mode 100644 index 0000000000..b53812b235 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyBuffer.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "EmptyBuffer.h" + +namespace cc { +namespace gfx { + +void EmptyBuffer::doInit(const BufferInfo &info) { +} + +void EmptyBuffer::doInit(const BufferViewInfo &info) { +} + +void EmptyBuffer::doResize(uint size) { +} + +void EmptyBuffer::doDestroy() { +} + +void EmptyBuffer::update(void *buffer, uint size) { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyBuffer.h b/native/cocos/renderer/gfx-empty/EmptyBuffer.h new file mode 100644 index 0000000000..32ea1dc9f8 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyBuffer.h @@ -0,0 +1,45 @@ +/**************************************************************************** + 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 "gfx-base/GFXBuffer.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyBuffer final : public Buffer { +public: + void update(void *buffer, uint size) override; + +protected: + void doInit(const BufferInfo &info) override; + void doInit(const BufferViewInfo &info) override; + void doResize(uint size) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.cpp b/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.cpp new file mode 100644 index 0000000000..f77a64fd8e --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "EmptyCommandBuffer.h" + +namespace cc { +namespace gfx { + +void EmptyCommandBuffer::doInit(const CommandBufferInfo &info) { +} + +void EmptyCommandBuffer::doDestroy() { +} + +void EmptyCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { +} + +void EmptyCommandBuffer::end() { +} + +void EmptyCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) { +} + +void EmptyCommandBuffer::endRenderPass() { +} + +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::bindInputAssembler(InputAssembler *ia) { +} + +void EmptyCommandBuffer::setViewport(const Viewport &vp) { +} + +void EmptyCommandBuffer::setScissor(const Rect &rect) { +} + +void EmptyCommandBuffer::setLineWidth(float width) { +} + +void EmptyCommandBuffer::setDepthBias(float constant, float clamp, float slope) { +} + +void EmptyCommandBuffer::setBlendConstants(const Color &constants) { +} + +void EmptyCommandBuffer::setDepthBound(float minBounds, float maxBounds) { +} + +void EmptyCommandBuffer::setStencilWriteMask(StencilFace face, uint mask) { +} + +void EmptyCommandBuffer::setStencilCompareMask(StencilFace face, int ref, uint mask) { +} + +void EmptyCommandBuffer::draw(InputAssembler *ia) { +} + +void EmptyCommandBuffer::updateBuffer(Buffer *buff, const void *data, uint size) { +} + +void EmptyCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { +} + +void EmptyCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint 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) { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.h b/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.h new file mode 100644 index 0000000000..86ece9d477 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyCommandBuffer.h @@ -0,0 +1,64 @@ +/**************************************************************************** + 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 "gfx-base/GFXCommandBuffer.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyCommandBuffer final : public CommandBuffer { +public: + void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void end() override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void endRenderPass() override; + void bindPipelineState(PipelineState *pso) override; + void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; + void bindInputAssembler(InputAssembler *ia) override; + void setViewport(const Viewport &vp) override; + void setScissor(const Rect &rect) override; + void setLineWidth(float width) override; + 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, int ref, uint mask) override; + void draw(InputAssembler *ia) 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 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; + +protected: + void doInit(const CommandBufferInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyContext.cpp b/native/cocos/renderer/gfx-empty/EmptyContext.cpp new file mode 100644 index 0000000000..ff3c1b4da4 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyContext.cpp @@ -0,0 +1,42 @@ +/**************************************************************************** + Copyright (c) 2019-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. +****************************************************************************/ + +#include "EmptyContext.h" + +namespace cc { +namespace gfx { + +bool EmptyContext::doInit(const ContextInfo &info) { + return true; +} + +void EmptyContext::doDestroy() { +} + +void EmptyContext::present() { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyContext.h b/native/cocos/renderer/gfx-empty/EmptyContext.h new file mode 100644 index 0000000000..835eca9b8b --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyContext.h @@ -0,0 +1,43 @@ +/**************************************************************************** + Copyright (c) 2019-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 "gfx-base/GFXContext.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyContext final : public Context { +public: + void present() override; + +protected: + bool doInit(const ContextInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyDescriptorSet.cpp b/native/cocos/renderer/gfx-empty/EmptyDescriptorSet.cpp new file mode 100644 index 0000000000..c1b416c767 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyDescriptorSet.cpp @@ -0,0 +1,41 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "EmptyDescriptorSet.h" + +namespace cc { +namespace gfx { + +void EmptyDescriptorSet::doInit(const DescriptorSetInfo &info) { +} + +void EmptyDescriptorSet::doDestroy() { +} + +void EmptyDescriptorSet::update() { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyDescriptorSet.h b/native/cocos/renderer/gfx-empty/EmptyDescriptorSet.h new file mode 100644 index 0000000000..1f426138ce --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyDescriptorSet.h @@ -0,0 +1,43 @@ +/**************************************************************************** + 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 "gfx-base/GFXDescriptorSet.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyDescriptorSet final : public DescriptorSet { +public: + void update() override; + +protected: + void doInit(const DescriptorSetInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyDescriptorSetLayout.cpp b/native/cocos/renderer/gfx-empty/EmptyDescriptorSetLayout.cpp new file mode 100644 index 0000000000..f67907acf9 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyDescriptorSetLayout.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "EmptyDescriptorSetLayout.h" + +namespace cc { +namespace gfx { + +void EmptyDescriptorSetLayout::doInit(const DescriptorSetLayoutInfo &info) { +} + +void EmptyDescriptorSetLayout::doDestroy() { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyDescriptorSetLayout.h b/native/cocos/renderer/gfx-empty/EmptyDescriptorSetLayout.h new file mode 100644 index 0000000000..4d5735945c --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyDescriptorSetLayout.h @@ -0,0 +1,41 @@ +/**************************************************************************** + 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 "gfx-base/GFXDescriptorSetLayout.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyDescriptorSetLayout final : public DescriptorSetLayout { +public: +protected: + void doInit(const DescriptorSetLayoutInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyDevice.cpp b/native/cocos/renderer/gfx-empty/EmptyDevice.cpp new file mode 100644 index 0000000000..a27c459ddd --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyDevice.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "base/CoreStd.h" + +#include "EmptyBuffer.h" +#include "EmptyCommandBuffer.h" +#include "EmptyContext.h" +#include "EmptyDescriptorSet.h" +#include "EmptyDescriptorSetLayout.h" +#include "EmptyDevice.h" +#include "EmptyFramebuffer.h" +#include "EmptyInputAssembler.h" +#include "EmptyPipelineLayout.h" +#include "EmptyPipelineState.h" +#include "EmptyQueue.h" +#include "EmptyRenderPass.h" +#include "EmptySampler.h" +#include "EmptyShader.h" +#include "EmptyTexture.h" + +namespace cc { +namespace gfx { + +EmptyDevice *EmptyDevice::_instance = nullptr; + +EmptyDevice *EmptyDevice::getInstance() { + return EmptyDevice::_instance; +} + +EmptyDevice::EmptyDevice() { + EmptyDevice::_instance = this; +} + +EmptyDevice::~EmptyDevice() { + EmptyDevice::_instance = nullptr; +} + +bool EmptyDevice::doInit(const DeviceInfo &info) { + ContextInfo ctxInfo; + ctxInfo.windowHandle = _windowHandle; + + _context = CC_NEW(EmptyContext); + if (!_context->initialize(ctxInfo)) { + destroy(); + return false; + } + + QueueInfo queueInfo; + queueInfo.type = QueueType::GRAPHICS; + _queue = createQueue(queueInfo); + + CommandBufferInfo cmdBuffInfo; + cmdBuffInfo.type = CommandBufferType::PRIMARY; + cmdBuffInfo.queue = _queue; + _cmdBuff = createCommandBuffer(cmdBuffInfo); + + CC_LOG_INFO("Empty device initialized."); + CC_LOG_INFO("SCREEN_SIZE: %d x %d", _width, _height); + CC_LOG_INFO("NATIVE_SIZE: %d x %d", _nativeWidth, _nativeHeight); + + return true; +} + +void EmptyDevice::doDestroy() { + CC_SAFE_DESTROY(_cmdBuff); + CC_SAFE_DESTROY(_queue); + CC_SAFE_DESTROY(_context); +} + +void EmptyDevice::resize(uint width, uint height) { + _width = _nativeWidth = width; + _height = _nativeHeight = height; +} + +void EmptyDevice::acquire() { +} + +void EmptyDevice::present() { + std::this_thread::sleep_for(std::chrono::milliseconds(16)); +} + +CommandBuffer *EmptyDevice::createCommandBuffer(const CommandBufferInfo &info, bool Emptyhas) { + return CC_NEW(EmptyCommandBuffer()); +} + +Queue *EmptyDevice::createQueue() { + return CC_NEW(EmptyQueue()); +} + +Buffer *EmptyDevice::createBuffer() { + return CC_NEW(EmptyBuffer()); +} + +Texture *EmptyDevice::createTexture() { + return CC_NEW(EmptyTexture()); +} + +Sampler *EmptyDevice::createSampler() { + return CC_NEW(EmptySampler()); +} + +Shader *EmptyDevice::createShader() { + return CC_NEW(EmptyShader()); +} + +InputAssembler *EmptyDevice::createInputAssembler() { + return CC_NEW(EmptyInputAssembler()); +} + +RenderPass *EmptyDevice::createRenderPass() { + return CC_NEW(EmptyRenderPass()); +} + +Framebuffer *EmptyDevice::createFramebuffer() { + return CC_NEW(EmptyFramebuffer()); +} + +DescriptorSet *EmptyDevice::createDescriptorSet() { + return CC_NEW(EmptyDescriptorSet()); +} + +DescriptorSetLayout *EmptyDevice::createDescriptorSetLayout() { + return CC_NEW(EmptyDescriptorSetLayout()); +} + +PipelineLayout *EmptyDevice::createPipelineLayout() { + return CC_NEW(EmptyPipelineLayout()); +} + +PipelineState *EmptyDevice::createPipelineState() { + return CC_NEW(EmptyPipelineState()); +} + +GlobalBarrier *EmptyDevice::createGlobalBarrier() { + return CC_NEW(GlobalBarrier()); +} + +TextureBarrier *EmptyDevice::createTextureBarrier() { + return CC_NEW(TextureBarrier()); +} + +void EmptyDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyDevice.h b/native/cocos/renderer/gfx-empty/EmptyDevice.h new file mode 100644 index 0000000000..8421390246 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyDevice.h @@ -0,0 +1,89 @@ +/**************************************************************************** + 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 "gfx-base/GFXDevice.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyDevice final : public Device { +public: + static EmptyDevice *getInstance(); + + ~EmptyDevice() override; + + using Device::copyBuffersToTexture; + using Device::createBuffer; + using Device::createCommandBuffer; + using Device::createDescriptorSet; + using Device::createDescriptorSetLayout; + using Device::createFramebuffer; + using Device::createGlobalBarrier; + using Device::createInputAssembler; + using Device::createPipelineLayout; + using Device::createPipelineState; + using Device::createQueue; + using Device::createRenderPass; + using Device::createSampler; + using Device::createShader; + using Device::createTexture; + using Device::createTextureBarrier; + + void resize(uint width, uint height) override; + void acquire() override; + void present() override; + + CommandBuffer * createCommandBuffer(const CommandBufferInfo &info, bool Emptyhas) override; + Queue * createQueue() override; + Buffer * createBuffer() override; + Texture * createTexture() override; + Sampler * createSampler() override; + Shader * createShader() override; + InputAssembler * createInputAssembler() override; + RenderPass * createRenderPass() override; + Framebuffer * createFramebuffer() override; + DescriptorSet * createDescriptorSet() override; + DescriptorSetLayout *createDescriptorSetLayout() override; + PipelineLayout * createPipelineLayout() override; + PipelineState * createPipelineState() override; + GlobalBarrier * createGlobalBarrier() override; + TextureBarrier * createTextureBarrier() override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; + +protected: + static EmptyDevice *_instance; + + friend class DeviceCreator; + + EmptyDevice(); + + bool doInit(const DeviceInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyFramebuffer.cpp b/native/cocos/renderer/gfx-empty/EmptyFramebuffer.cpp new file mode 100644 index 0000000000..b352e948ac --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyFramebuffer.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "EmptyFramebuffer.h" + +namespace cc { +namespace gfx { + +void EmptyFramebuffer::doInit(const FramebufferInfo &info) { +} + +void EmptyFramebuffer::doDestroy() { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyFramebuffer.h b/native/cocos/renderer/gfx-empty/EmptyFramebuffer.h new file mode 100644 index 0000000000..0d99fe532e --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyFramebuffer.h @@ -0,0 +1,41 @@ +/**************************************************************************** + 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 "gfx-base/GFXFramebuffer.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyFramebuffer final : public Framebuffer { +public: +protected: + void doInit(const FramebufferInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyInputAssembler.cpp b/native/cocos/renderer/gfx-empty/EmptyInputAssembler.cpp new file mode 100644 index 0000000000..9b6d09e2a7 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyInputAssembler.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "EmptyInputAssembler.h" + +namespace cc { +namespace gfx { + +void EmptyInputAssembler::doInit(const InputAssemblerInfo &info) { +} + +void EmptyInputAssembler::doDestroy() { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyInputAssembler.h b/native/cocos/renderer/gfx-empty/EmptyInputAssembler.h new file mode 100644 index 0000000000..4cf915c446 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyInputAssembler.h @@ -0,0 +1,41 @@ +/**************************************************************************** + 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 "gfx-base/GFXInputAssembler.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyInputAssembler final : public InputAssembler { +public: +protected: + void doInit(const InputAssemblerInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyPipelineLayout.cpp b/native/cocos/renderer/gfx-empty/EmptyPipelineLayout.cpp new file mode 100644 index 0000000000..7eb88fee98 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyPipelineLayout.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "EmptyPipelineLayout.h" + +namespace cc { +namespace gfx { + +void EmptyPipelineLayout::doInit(const PipelineLayoutInfo &info) { +} + +void EmptyPipelineLayout::doDestroy() { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyPipelineLayout.h b/native/cocos/renderer/gfx-empty/EmptyPipelineLayout.h new file mode 100644 index 0000000000..b4c106e550 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyPipelineLayout.h @@ -0,0 +1,41 @@ +/**************************************************************************** + 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 "gfx-base/GFXPipelineLayout.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyPipelineLayout final : public PipelineLayout { +public: +protected: + void doInit(const PipelineLayoutInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyPipelineState.cpp b/native/cocos/renderer/gfx-empty/EmptyPipelineState.cpp new file mode 100644 index 0000000000..dadfe6d173 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyPipelineState.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "EmptyPipelineState.h" + +namespace cc { +namespace gfx { + +void EmptyPipelineState::doInit(const PipelineStateInfo &info) { +} + +void EmptyPipelineState::doDestroy() { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyPipelineState.h b/native/cocos/renderer/gfx-empty/EmptyPipelineState.h new file mode 100644 index 0000000000..ebcc309516 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyPipelineState.h @@ -0,0 +1,41 @@ +/**************************************************************************** + 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 "gfx-base/GFXPipelineState.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyPipelineState final : public PipelineState { +public: +protected: + void doInit(const PipelineStateInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyQueue.cpp b/native/cocos/renderer/gfx-empty/EmptyQueue.cpp new file mode 100644 index 0000000000..fc282fd457 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyQueue.cpp @@ -0,0 +1,41 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "EmptyQueue.h" + +namespace cc { +namespace gfx { + +void EmptyQueue::doInit(const QueueInfo &info) { +} + +void EmptyQueue::doDestroy() { +} + +void EmptyQueue::submit(CommandBuffer *const *cmdBuffs, uint count) { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyQueue.h b/native/cocos/renderer/gfx-empty/EmptyQueue.h new file mode 100644 index 0000000000..b74d22b06d --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyQueue.h @@ -0,0 +1,45 @@ +/**************************************************************************** + 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 "gfx-base/GFXQueue.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyQueue final : public Queue { +public: + using Queue::submit; + + void submit(CommandBuffer *const *cmdBuffs, uint count) override; + +protected: + void doInit(const QueueInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyRenderPass.cpp b/native/cocos/renderer/gfx-empty/EmptyRenderPass.cpp new file mode 100644 index 0000000000..b9f17fb79d --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyRenderPass.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "EmptyRenderPass.h" + +namespace cc { +namespace gfx { + +void EmptyRenderPass::doInit(const RenderPassInfo &info) { +} + +void EmptyRenderPass::doDestroy() { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyRenderPass.h b/native/cocos/renderer/gfx-empty/EmptyRenderPass.h new file mode 100644 index 0000000000..96e0c6cf83 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyRenderPass.h @@ -0,0 +1,41 @@ +/**************************************************************************** + 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 "gfx-base/GFXRenderPass.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyRenderPass final : public RenderPass { +public: +protected: + void doInit(const RenderPassInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptySampler.cpp b/native/cocos/renderer/gfx-empty/EmptySampler.cpp new file mode 100644 index 0000000000..de1a9285bb --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptySampler.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "EmptySampler.h" + +namespace cc { +namespace gfx { + +void EmptySampler::doInit(const SamplerInfo &info) { +} + +void EmptySampler::doDestroy() { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptySampler.h b/native/cocos/renderer/gfx-empty/EmptySampler.h new file mode 100644 index 0000000000..b09dc12044 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptySampler.h @@ -0,0 +1,41 @@ +/**************************************************************************** + 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 "gfx-base/GFXSampler.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptySampler final : public Sampler { +public: +protected: + void doInit(const SamplerInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyShader.cpp b/native/cocos/renderer/gfx-empty/EmptyShader.cpp new file mode 100644 index 0000000000..47f6f0a91a --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyShader.cpp @@ -0,0 +1,41 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "base/CoreStd.h" + +#include "EmptyShader.h" + +namespace cc { +namespace gfx { + +void EmptyShader::doInit(const ShaderInfo &info) { + CC_LOG_INFO("Shader '%s' compilation succeeded.", info.name.c_str()); +} + +void EmptyShader::doDestroy() { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyShader.h b/native/cocos/renderer/gfx-empty/EmptyShader.h new file mode 100644 index 0000000000..a42aaa6f3d --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyShader.h @@ -0,0 +1,41 @@ +/**************************************************************************** + 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 "gfx-base/GFXShader.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyShader final : public Shader { +public: +protected: + void doInit(const ShaderInfo &info) override; + void doDestroy() override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyTexture.cpp b/native/cocos/renderer/gfx-empty/EmptyTexture.cpp new file mode 100644 index 0000000000..f27ec3deeb --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyTexture.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** + 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. +****************************************************************************/ + +#include "EmptyTexture.h" + +namespace cc { +namespace gfx { + +void EmptyTexture::doInit(const TextureInfo &info) { +} + +void EmptyTexture::doInit(const TextureViewInfo &info) { +} + +void EmptyTexture::doDestroy() { +} + +void EmptyTexture::doResize(uint width, uint height) { +} + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-empty/EmptyTexture.h b/native/cocos/renderer/gfx-empty/EmptyTexture.h new file mode 100644 index 0000000000..c4bfbf3205 --- /dev/null +++ b/native/cocos/renderer/gfx-empty/EmptyTexture.h @@ -0,0 +1,43 @@ +/**************************************************************************** + 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 "gfx-base/GFXTexture.h" + +namespace cc { +namespace gfx { + +class CC_DLL EmptyTexture final : public Texture { +public: +protected: + void doInit(const TextureInfo &info) override; + void doInit(const TextureViewInfo &info) override; + void doDestroy() override; + void doResize(uint width, uint height) override; +}; + +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h b/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h index af0a9e39d0..a05ff4562d 100644 --- a/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h +++ b/native/cocos/renderer/gfx-gles-common/GLESCommandPool.h @@ -56,7 +56,7 @@ public: #define INITIAL_CAPACITY 1 -template ::value>> +template ::value>> class CommandPool { public: CommandPool() : _freeCmds(INITIAL_CAPACITY) { @@ -128,7 +128,7 @@ public: _freeCmds.clear(); } -private: +protected: T **_frees = nullptr; uint _count = 0; CachedArray _freeCmds; diff --git a/native/cocos/renderer/gfx-gles2/GFXGLES2.h b/native/cocos/renderer/gfx-gles2/GFXGLES2.h index c6921324eb..35859993b1 100644 --- a/native/cocos/renderer/gfx-gles2/GFXGLES2.h +++ b/native/cocos/renderer/gfx-gles2/GFXGLES2.h @@ -23,10 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_H_ -#define CC_GFXGLES2_H_ +#pragma once #include "GLES2Std.h" #include "GLES2Device.h" - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp index 27590a3a96..6d8d4a032d 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Buffer.cpp @@ -25,74 +25,46 @@ #include "GLES2Std.h" -#include "GLES2Device.h" #include "GLES2Buffer.h" #include "GLES2Commands.h" +#include "GLES2Device.h" namespace cc { namespace gfx { -GLES2Buffer::GLES2Buffer(Device *device) -: Buffer(device) { +GLES2Buffer::GLES2Buffer() +: Buffer() { } GLES2Buffer::~GLES2Buffer() { } -bool GLES2Buffer::initialize(const BufferInfo &info) { - - _usage = info.usage; - _memUsage = info.memUsage; - _size = info.size; - _stride = std::max(info.stride, 1u); - _count = _size / _stride; - _flags = info.flags; - - _gpuBuffer = CC_NEW(GLES2GPUBuffer); - if (!_gpuBuffer) { - CC_LOG_ERROR("GLES2Buffer: CC_NEW GLES2GPUBuffer failed."); - return false; - } - _gpuBuffer->usage = _usage; +void GLES2Buffer::doInit(const BufferInfo &info) { + _gpuBuffer = CC_NEW(GLES2GPUBuffer); + _gpuBuffer->usage = _usage; _gpuBuffer->memUsage = _memUsage; - _gpuBuffer->size = _size; - _gpuBuffer->stride = _stride; - _gpuBuffer->count = _count; + _gpuBuffer->size = _size; + _gpuBuffer->stride = _stride; + _gpuBuffer->count = _count; if (_usage & BufferUsageBit::INDIRECT) { _gpuBuffer->indirects.resize(_count); } - GLES2CmdFuncCreateBuffer((GLES2Device *)_device, _gpuBuffer); - _device->getMemoryStatus().bufferSize += _size; - - return true; + GLES2CmdFuncCreateBuffer(GLES2Device::getInstance(), _gpuBuffer); } -bool GLES2Buffer::initialize(const BufferViewInfo &info) { - - _isBufferView = true; - - GLES2Buffer *buffer = (GLES2Buffer *)info.buffer; - - _usage = buffer->_usage; - _memUsage = buffer->_memUsage; - _size = _stride = info.range; - _count = 1u; - _flags = buffer->_flags; - - _gpuBufferView = CC_NEW(GLES2GPUBufferView); +void GLES2Buffer::doInit(const BufferViewInfo &info) { + GLES2Buffer *buffer = (GLES2Buffer *)info.buffer; + _gpuBufferView = CC_NEW(GLES2GPUBufferView); _gpuBufferView->gpuBuffer = buffer->gpuBuffer(); - _gpuBufferView->range = _size; - _gpuBufferView->offset = info.offset; - - return true; + _gpuBufferView->range = _size; + _gpuBufferView->offset = info.offset; } -void GLES2Buffer::destroy() { +void GLES2Buffer::doDestroy() { if (_gpuBuffer) { - GLES2CmdFuncDestroyBuffer((GLES2Device *)_device, _gpuBuffer); - _device->getMemoryStatus().bufferSize -= _size; + GLES2CmdFuncDestroyBuffer(GLES2Device::getInstance(), _gpuBuffer); CC_DELETE(_gpuBuffer); _gpuBuffer = nullptr; } @@ -100,21 +72,10 @@ void GLES2Buffer::destroy() { CC_SAFE_DELETE(_gpuBufferView); } -void GLES2Buffer::resize(uint size) { - CCASSERT(!_isBufferView, "Cannot resize buffer views"); - - if (_size != size) { - const uint oldSize = _size; - _size = size; - _count = _size / _stride; - - MemoryStatus &status = _device->getMemoryStatus(); - _gpuBuffer->size = _size; - _gpuBuffer->count = _count; - GLES2CmdFuncResizeBuffer((GLES2Device *)_device, _gpuBuffer); - status.bufferSize -= oldSize; - status.bufferSize += _size; - } +void GLES2Buffer::doResize(uint size) { + _gpuBuffer->size = _size; + _gpuBuffer->count = _count; + GLES2CmdFuncResizeBuffer(GLES2Device::getInstance(), _gpuBuffer); } void GLES2Buffer::update(void *buffer, uint size) { @@ -122,7 +83,7 @@ void GLES2Buffer::update(void *buffer, uint size) { CCASSERT(size != 0, "Should not update buffer with 0 bytes of data"); CCASSERT(buffer, "Buffer should not be nullptr"); - GLES2CmdFuncUpdateBuffer((GLES2Device *)_device, _gpuBuffer, buffer, 0u, size); + GLES2CmdFuncUpdateBuffer(GLES2Device::getInstance(), _gpuBuffer, buffer, 0u, size); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles2/GLES2Buffer.h b/native/cocos/renderer/gfx-gles2/GLES2Buffer.h index 2c28fe204c..46e9e78522 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Buffer.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Buffer.h @@ -35,21 +35,21 @@ class GLES2GPUBufferView; class CC_GLES2_API GLES2Buffer final : public Buffer { public: - GLES2Buffer(Device *device); + GLES2Buffer(); ~GLES2Buffer(); -public: - bool initialize(const BufferInfo &info) override; - bool initialize(const BufferViewInfo &info) override; - void destroy() override; - void resize(uint size) override; void update(void *buffer, uint size) override; CC_INLINE GLES2GPUBuffer *gpuBuffer() const { return _gpuBuffer; } CC_INLINE GLES2GPUBufferView *gpuBufferView() const { return _gpuBufferView; } -private: - GLES2GPUBuffer *_gpuBuffer = nullptr; +protected: + void doInit(const BufferInfo &info) override; + void doInit(const BufferViewInfo &info) override; + void doDestroy() override; + void doResize(uint size) 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 7a66e9b124..f51ad0f7a2 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.cpp @@ -38,28 +38,26 @@ namespace cc { namespace gfx { -GLES2CommandBuffer::GLES2CommandBuffer(Device *device) -: CommandBuffer(device) { +GLES2CommandBuffer::GLES2CommandBuffer() +: CommandBuffer() { } GLES2CommandBuffer::~GLES2CommandBuffer() { } -bool GLES2CommandBuffer::initialize(const CommandBufferInfo &info) { +void GLES2CommandBuffer::doInit(const CommandBufferInfo &info) { _type = info.type; _queue = info.queue; _cmdAllocator = CC_NEW(GLES2GPUCommandAllocator); _curCmdPackage = CC_NEW(GLES2CmdPackage); - size_t setCount = ((GLES2Device *)_device)->bindingMappingInfo().bufferOffsets.size(); + size_t setCount = GLES2Device::getInstance()->bindingMappingInfo().bufferOffsets.size(); _curGPUDescriptorSets.resize(setCount); _curDynamicOffsets.resize(setCount); - - return true; } -void GLES2CommandBuffer::destroy() { +void GLES2CommandBuffer::doDestroy() { _cmdAllocator->clearCmds(_curCmdPackage); CC_SAFE_DELETE(_curCmdPackage); diff --git a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h index c3c9736032..ca0a7ec31d 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h +++ b/native/cocos/renderer/gfx-gles2/GLES2CommandBuffer.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_COMMAND_BUFFER_H_ -#define CC_GFXGLES2_COMMAND_BUFFER_H_ +#pragma once #include "gfx-base/GFXCommandBuffer.h" #include "GLES2Commands.h" @@ -36,39 +35,38 @@ class GLES2GPUCommandAllocator; class CC_GLES2_API GLES2CommandBuffer : public CommandBuffer { public: - GLES2CommandBuffer(Device *device); + GLES2CommandBuffer(); ~GLES2CommandBuffer(); friend class GLES2Queue; -public: - virtual bool initialize(const CommandBufferInfo &info) override; - virtual void destroy() override; - - virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; - virtual void end() override; - virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; - virtual void endRenderPass() override; - virtual void bindPipelineState(PipelineState *pso) override; - virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; - virtual void bindInputAssembler(InputAssembler *ia) override; - virtual void setViewport(const Viewport &vp) override; - virtual void setScissor(const Rect &rect) override; - virtual void setLineWidth(float width) override; - virtual void setDepthBias(float constant, float clamp, float slope) override; - virtual void setBlendConstants(const Color &constants) override; - virtual void setDepthBound(float minBounds, float maxBounds) override; - virtual void setStencilWriteMask(StencilFace face, uint mask) override; - virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) override; - virtual void draw(InputAssembler *ia) override; - virtual void updateBuffer(Buffer *buff, const void *data, uint size) override; - virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; - virtual void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; - virtual void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; - virtual void dispatch(const DispatchInfo &info) override {} - virtual void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) override {} + void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void end() override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void endRenderPass() override; + void bindPipelineState(PipelineState *pso) override; + void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; + void bindInputAssembler(InputAssembler *ia) override; + void setViewport(const Viewport &vp) override; + void setScissor(const Rect &rect) override; + void setLineWidth(float width) override; + 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, int ref, uint mask) override; + void draw(InputAssembler *ia) 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 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 {} protected: + void doInit(const CommandBufferInfo &info) override; + void doDestroy() override; + void BindStates(); GLES2GPUCommandAllocator *_cmdAllocator = nullptr; @@ -93,5 +91,3 @@ protected: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2Commands.h b/native/cocos/renderer/gfx-gles2/GLES2Commands.h index 1912c597af..5a92b02340 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Commands.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Commands.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_COMMANDS_H_ -#define CC_GFXGLES2_COMMANDS_H_ +#pragma once #include "../gfx-gles-common/GLESCommandPool.h" #include "GLES2GPUObjects.h" @@ -84,7 +83,7 @@ public: GLES2CmdBeginRenderPass() : GLESCmd(GLESCmdType::BEGIN_RENDER_PASS) {} - virtual void clear() override { + void clear() override { gpuFBO = nullptr; numClearColors = 0; } @@ -120,7 +119,7 @@ public: GLES2CmdBindStates() : GLESCmd(GLESCmdType::BIND_STATES) {} - virtual void clear() override { + void clear() override { gpuPipelineState = nullptr; gpuInputAssembler = nullptr; gpuDescriptorSets.clear(); @@ -133,7 +132,7 @@ public: DrawInfo drawInfo; GLES2CmdDraw() : GLESCmd(GLESCmdType::DRAW) {} - virtual void clear() override {} + void clear() override {} }; class GLES2CmdUpdateBuffer final : public GLESCmd { @@ -145,7 +144,7 @@ public: GLES2CmdUpdateBuffer() : GLESCmd(GLESCmdType::UPDATE_BUFFER) {} - virtual void clear() override { + void clear() override { gpuBuffer = nullptr; buffer = nullptr; } @@ -160,7 +159,7 @@ public: GLES2CmdCopyBufferToTexture() : GLESCmd(GLESCmdType::COPY_BUFFER_TO_TEXTURE) {} - virtual void clear() override { + void clear() override { gpuTexture = nullptr; regions = nullptr; count = 0u; @@ -245,5 +244,3 @@ CC_GLES2_API void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage * } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2Context.cpp b/native/cocos/renderer/gfx-gles2/GLES2Context.cpp index fc449d6c39..89b2788a2e 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Context.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Context.cpp @@ -91,8 +91,8 @@ void GL_APIENTRY GLES2EGLDebugProc(GLenum source, #endif -GLES2Context::GLES2Context(Device *device) -: Context(device) { +GLES2Context::GLES2Context() +: Context() { } GLES2Context::~GLES2Context() { @@ -100,18 +100,18 @@ GLES2Context::~GLES2Context() { #if (CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_MAC_OSX) -bool GLES2Context::initialize(const ContextInfo &info) { +bool GLES2Context::doInit(const ContextInfo &info) { _vsyncMode = info.vsyncMode; _windowHandle = info.windowHandle; ////////////////////////////////////////////////////////////////////////// - if (!gles2wInit()) { - return false; - } - if (!info.sharedCtx) { + if (!gles2wInit()) { + return false; + } + _isPrimaryContex = true; _windowHandle = info.windowHandle; @@ -216,8 +216,8 @@ bool GLES2Context::initialize(const ContextInfo &info) { return false; } - uint width = _device->getWidth(); - uint height = _device->getHeight(); + uint width = GLES2Device::getInstance()->getWidth(); + uint height = GLES2Device::getInstance()->getHeight(); ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, nFmt); #endif @@ -260,26 +260,25 @@ bool GLES2Context::initialize(const ContextInfo &info) { return false; } - _eglSharedContext = _eglContext; - - #if (CC_PLATFORM == CC_PLATFORM_ANDROID) - EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [=](const CustomEvent &) -> void { +#if (CC_PLATFORM == CC_PLATFORM_ANDROID) + EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [=](const CustomEvent & /*unused*/) -> void { if (_eglSurface != EGL_NO_SURFACE) { eglDestroySurface(_eglDisplay, _eglSurface); _eglSurface = EGL_NO_SURFACE; } }); + // guaranteed to be invoked in the order they were added EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [=](const CustomEvent &event) -> void { _windowHandle = (uintptr_t)event.args->ptrVal; - EGLint nFmt; + EGLint nFmt = 0; if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { CC_LOG_ERROR("Getting configuration attributes failed."); return; } - uint width = _device->getWidth(); - uint height = _device->getHeight(); + uint width = GLES2Device::getInstance()->getWidth(); + uint height = GLES2Device::getInstance()->getHeight(); ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, nFmt); EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, (EGLNativeWindowType)_windowHandle, NULL)); @@ -288,14 +287,12 @@ bool GLES2Context::initialize(const ContextInfo &info) { return; } - ((GLES2Context *)_device->getContext())->MakeCurrent(); - ((GLES2Device *)_device)->stateCache()->reset(); + ((GLES2Context *)GLES2Device::getInstance()->getContext())->MakeCurrent(); + GLES2Device::getInstance()->stateCache()->reset(); }); - #endif +#endif - if (!gles2wInit()) { - return false; - } + _eglSharedContext = _eglContext; } else { GLES2Context *sharedCtx = (GLES2Context *)info.sharedCtx; @@ -351,7 +348,7 @@ bool GLES2Context::initialize(const ContextInfo &info) { return true; } -void GLES2Context::destroy() { +void GLES2Context::doDestroy() { EGL_CHECK(eglMakeCurrent(_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); if (_eglContext != EGL_NO_CONTEXT) { @@ -359,21 +356,23 @@ void GLES2Context::destroy() { _eglContext = EGL_NO_CONTEXT; } - if (_isPrimaryContex && _eglSurface != EGL_NO_SURFACE) { - EGL_CHECK(eglDestroySurface(_eglDisplay, _eglSurface)); - _eglSurface = EGL_NO_SURFACE; - } + if (_isPrimaryContex) { + if (_eglSurface != EGL_NO_SURFACE) { + EGL_CHECK(eglDestroySurface(_eglDisplay, _eglSurface)); + _eglSurface = EGL_NO_SURFACE; + } - if (_eglDisplay != EGL_NO_DISPLAY) { - EGL_CHECK(eglTerminate(_eglDisplay)); - _eglDisplay = EGL_NO_DISPLAY; - } + if (_eglDisplay != EGL_NO_DISPLAY) { + EGL_CHECK(eglTerminate(_eglDisplay)); + _eglDisplay = EGL_NO_DISPLAY; + } #if (CC_PLATFORM == CC_PLATFORM_WINDOWS) - if (_isPrimaryContex && _nativeDisplay) { - ReleaseDC((HWND)_windowHandle, _nativeDisplay); - } + if (_nativeDisplay) { + ReleaseDC((HWND)_windowHandle, _nativeDisplay); + } #endif + } _isPrimaryContex = false; _windowHandle = 0; diff --git a/native/cocos/renderer/gfx-gles2/GLES2Context.h b/native/cocos/renderer/gfx-gles2/GLES2Context.h index 8ca5c8b092..a0426527f9 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Context.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Context.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_EGL_CONTEXT_H_ -#define CC_GFXGLES2_EGL_CONTEXT_H_ +#pragma once #include "gfx-base/GFXContext.h" #include "GLES2Wrangler.h" @@ -34,13 +33,10 @@ namespace gfx { class CC_GLES2_API GLES2Context final : public Context { public: - GLES2Context(Device *device); + GLES2Context(); ~GLES2Context(); -public: - virtual bool initialize(const ContextInfo &info) override; - virtual void destroy() override; - virtual void present() override; + void present() override; bool MakeCurrent(bool bound); bool CheckExtension(const String &extension) const; @@ -61,15 +57,17 @@ public: CC_INLINE int major_ver() const { return _majorVersion; } CC_INLINE int minor_ver() const { return _minorVersion; } -private: bool MakeCurrentImpl(bool bound); #if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) bool createCustomFrameBuffer(); - void destroyCustomFrameBuffer(); + void doDestroyCustomFrameBuffer(); #endif -private: +protected: + bool doInit(const ContextInfo &info) override; + void doDestroy() override; + bool _isPrimaryContex = false; #if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) intptr_t _eaglContext = 0; @@ -94,5 +92,3 @@ private: } // namespace gfx } // namespace cc - -#endif // CC_GFXGLES2_EGL_CONTEXT_H_ diff --git a/native/cocos/renderer/gfx-gles2/GLES2Context.mm b/native/cocos/renderer/gfx-gles2/GLES2Context.mm index 80270d7eed..8c52b47486 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Context.mm +++ b/native/cocos/renderer/gfx-gles2/GLES2Context.mm @@ -38,7 +38,7 @@ namespace gfx { #if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) -bool GLES2Context::initialize(const ContextInfo &info) { +void GLES2Context::doInit(const ContextInfo &info) { _vsyncMode = info.vsyncMode; _windowHandle = info.windowHandle; @@ -191,7 +191,7 @@ void GLES2Context::destroyCustomFrameBuffer() } } -void GLES2Context::destroy() { +void GLES2Context::doDestroy() { destroyCustomFrameBuffer(); if (_eaglContext) { diff --git a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp index 9f35a1a26e..e0f7be88a9 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.cpp @@ -35,17 +35,14 @@ namespace cc { namespace gfx { -GLES2DescriptorSet::GLES2DescriptorSet(Device *device) -: DescriptorSet(device) { +GLES2DescriptorSet::GLES2DescriptorSet() +: DescriptorSet() { } GLES2DescriptorSet::~GLES2DescriptorSet() { } -bool GLES2DescriptorSet::initialize(const DescriptorSetInfo &info) { - - _layout = info.layout; - +void GLES2DescriptorSet::doInit(const DescriptorSetInfo &info) { const GLES2GPUDescriptorSetLayout *gpuDescriptorSetLayout = ((GLES2DescriptorSetLayout *)_layout)->gpuDescriptorSetLayout(); const size_t descriptorCount = gpuDescriptorSetLayout->descriptorCount; const size_t bindingCount = gpuDescriptorSetLayout->bindings.size(); @@ -64,19 +61,13 @@ bool GLES2DescriptorSet::initialize(const DescriptorSetInfo &info) { } _gpuDescriptorSet->descriptorIndices = &gpuDescriptorSetLayout->descriptorIndices; - - return true; } -void GLES2DescriptorSet::destroy() { +void GLES2DescriptorSet::doDestroy() { if (_gpuDescriptorSet) { CC_DELETE(_gpuDescriptorSet); _gpuDescriptorSet = nullptr; } - // do remember to clear these or else it might not be properly updated when reused - _buffers.clear(); - _textures.clear(); - _samplers.clear(); } void GLES2DescriptorSet::update() { diff --git a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.h b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.h index abeaba8e37..42afbd8b90 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.h +++ b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSet.h @@ -35,17 +35,17 @@ class GLES2GPUDescriptorSet; class CC_GLES2_API GLES2DescriptorSet final : public DescriptorSet { public: - GLES2DescriptorSet(Device *device); + GLES2DescriptorSet(); ~GLES2DescriptorSet(); -public: - virtual bool initialize(const DescriptorSetInfo &info) override; - virtual void destroy() override; - virtual void update() override; + void update() override; CC_INLINE GLES2GPUDescriptorSet *gpuDescriptorSet() const { return _gpuDescriptorSet; } -private: +protected: + void doInit(const DescriptorSetInfo &info) override; + void doDestroy() override; + GLES2GPUDescriptorSet *_gpuDescriptorSet = nullptr; }; diff --git a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cpp b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cpp index 25560f9c62..3845c1b9e1 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.cpp @@ -31,45 +31,21 @@ namespace cc { namespace gfx { -GLES2DescriptorSetLayout::GLES2DescriptorSetLayout(Device *device) -: DescriptorSetLayout(device) { +GLES2DescriptorSetLayout::GLES2DescriptorSetLayout() +: DescriptorSetLayout() { } GLES2DescriptorSetLayout::~GLES2DescriptorSetLayout() { } -bool GLES2DescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { - - _bindings = info.bindings; - size_t bindingCount = _bindings.size(); - _descriptorCount = 0u; - - if (bindingCount) { - uint maxBinding = 0u; - vector flattenedIndices(bindingCount); - for (uint i = 0u; i < bindingCount; i++) { - const DescriptorSetLayoutBinding &binding = _bindings[i]; - flattenedIndices[i] = _descriptorCount; - _descriptorCount += binding.count; - if (binding.binding > maxBinding) maxBinding = binding.binding; - } - - _bindingIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); - _descriptorIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); - for (uint i = 0u; i < bindingCount; i++) { - const DescriptorSetLayoutBinding &binding = _bindings[i]; - _bindingIndices[binding.binding] = i; - _descriptorIndices[binding.binding] = flattenedIndices[i]; - } - } - +void GLES2DescriptorSetLayout::doInit(const DescriptorSetLayoutInfo &info) { _gpuDescriptorSetLayout = CC_NEW(GLES2GPUDescriptorSetLayout); _gpuDescriptorSetLayout->descriptorCount = _descriptorCount; _gpuDescriptorSetLayout->bindingIndices = _bindingIndices; _gpuDescriptorSetLayout->descriptorIndices = _descriptorIndices; _gpuDescriptorSetLayout->bindings = _bindings; - for (uint i = 0u; i < bindingCount; i++) { + for (uint i = 0u; i < _bindings.size(); i++) { const DescriptorSetLayoutBinding &binding = _bindings[i]; if (binding.descriptorType & DESCRIPTOR_DYNAMIC_TYPE) { for (uint j = 0u; j < binding.count; j++) { @@ -77,10 +53,9 @@ bool GLES2DescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { } } } - return true; } -void GLES2DescriptorSetLayout::destroy() { +void GLES2DescriptorSetLayout::doDestroy() { if (_gpuDescriptorSetLayout) { CC_DELETE(_gpuDescriptorSetLayout); _gpuDescriptorSetLayout = nullptr; diff --git a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.h b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.h index 541f647ad7..811cf34307 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.h +++ b/native/cocos/renderer/gfx-gles2/GLES2DescriptorSetLayout.h @@ -35,16 +35,15 @@ class GLES2GPUDescriptorSetLayout; class CC_GLES2_API GLES2DescriptorSetLayout final : public DescriptorSetLayout { public: - GLES2DescriptorSetLayout(Device *device); + GLES2DescriptorSetLayout(); ~GLES2DescriptorSetLayout(); -public: - virtual bool initialize(const DescriptorSetLayoutInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES2GPUDescriptorSetLayout *gpuDescriptorSetLayout() const { return _gpuDescriptorSetLayout; } -private: +protected: + void doInit(const DescriptorSetLayoutInfo &info) override; + void doDestroy() override; + GLES2GPUDescriptorSetLayout *_gpuDescriptorSetLayout = nullptr; }; diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp index 053f5ccc46..2483938d02 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.cpp @@ -45,45 +45,49 @@ namespace cc { namespace gfx { +GLES2Device *GLES2Device::_instance = nullptr; + +GLES2Device *GLES2Device::getInstance() { + return GLES2Device::_instance; +} + GLES2Device::GLES2Device() { + _API = API::GLES2; + _deviceName = "GLES2"; + + GLES2Device::_instance = this; } GLES2Device::~GLES2Device() { + GLES2Device::_instance = nullptr; } -bool GLES2Device::initialize(const DeviceInfo &info) { - _API = API::GLES2; - _deviceName = "GLES2"; - _width = info.width; - _height = info.height; - _nativeWidth = info.nativeWidth; - _nativeHeight = info.nativeHeight; - _windowHandle = info.windowHandle; - - _bindingMappingInfo = info.bindingMappingInfo; - if (!_bindingMappingInfo.bufferOffsets.size()) { - _bindingMappingInfo.bufferOffsets.push_back(0); - } - if (!_bindingMappingInfo.samplerOffsets.size()) { - _bindingMappingInfo.samplerOffsets.push_back(0); - } - - _gpuStateCache = CC_NEW(GLES2GPUStateCache); - _gpuStagingBufferPool = CC_NEW(GLES2GPUStagingBufferPool); - +bool GLES2Device::doInit(const DeviceInfo &info) { ContextInfo ctxInfo; ctxInfo.windowHandle = _windowHandle; - ctxInfo.sharedCtx = info.sharedCtx; - _renderContext = CC_NEW(GLES2Context(this)); + _renderContext = CC_NEW(GLES2Context); if (!_renderContext->initialize(ctxInfo)) { destroy(); return false; } + + QueueInfo queueInfo; + queueInfo.type = QueueType::GRAPHICS; + _queue = createQueue(queueInfo); + + CommandBufferInfo cmdBuffInfo; + cmdBuffInfo.type = CommandBufferType::PRIMARY; + cmdBuffInfo.queue = _queue; + _cmdBuff = createCommandBuffer(cmdBuffInfo); + + _gpuStateCache = CC_NEW(GLES2GPUStateCache); + _gpuStagingBufferPool = CC_NEW(GLES2GPUStagingBufferPool); + bindRenderContext(true); String extStr = (const char *)glGetString(GL_EXTENSIONS); - _extensions = StringUtil::Split(extStr, " "); + _extensions = StringUtil::Split(extStr, " "); if (checkExtension("GL_OES_texture_float")) { _features[(int)Feature::TEXTURE_FLOAT] = true; @@ -94,8 +98,8 @@ bool GLES2Device::initialize(const DeviceInfo &info) { } _features[(int)Feature::FORMAT_R11G11B10F] = true; - _features[(int)Feature::FORMAT_D24S8] = true; - _features[(int)Feature::MSAA] = true; + _features[(int)Feature::FORMAT_D24S8] = true; + _features[(int)Feature::MSAA] = true; if (checkExtension("GL_OES_element_index_uint")) { _features[(int)Feature::ELEMENT_INDEX_UINT] = true; @@ -119,10 +123,10 @@ bool GLES2Device::initialize(const DeviceInfo &info) { if (checkExtension("blend_minmax")) _features[(int)Feature::BLEND_MINMAX] = true; - _useVAO = checkExtension("vertex_array_object"); - _useDrawInstanced = checkExtension("draw_instanced"); + _useVAO = checkExtension("vertex_array_object"); + _useDrawInstanced = checkExtension("draw_instanced"); _useInstancedArrays = _features[(int)Feature::INSTANCED_ARRAYS] = checkExtension("instanced_arrays"); - _useDiscardFramebuffer = checkExtension("discard_framebuffer"); + _useDiscardFramebuffer = checkExtension("discard_framebuffer"); String compressedFmts; @@ -145,21 +149,21 @@ bool GLES2Device::initialize(const DeviceInfo &info) { _features[(int)Feature::FORMAT_ASTC] = true; compressedFmts += "astc "; } - _features[static_cast(Feature::DEPTH_BOUNDS)] = true; - _features[static_cast(Feature::LINE_WIDTH)] = true; + _features[static_cast(Feature::DEPTH_BOUNDS)] = true; + _features[static_cast(Feature::LINE_WIDTH)] = true; _features[static_cast(Feature::STENCIL_COMPARE_MASK)] = true; - _features[static_cast(Feature::STENCIL_WRITE_MASK)] = true; - _features[static_cast(Feature::FORMAT_RGB8)] = true; + _features[static_cast(Feature::STENCIL_WRITE_MASK)] = true; + _features[static_cast(Feature::FORMAT_RGB8)] = true; if (checkExtension("depth_texture")) { - _features[static_cast(Feature::FORMAT_D16)] = true; - _features[static_cast(Feature::FORMAT_D24)] = true; + _features[static_cast(Feature::FORMAT_D16)] = true; + _features[static_cast(Feature::FORMAT_D24)] = true; _features[static_cast(Feature::FORMAT_D24S8)] = checkExtension("packed_depth_stencil"); } _renderer = (const char *)glGetString(GL_RENDERER); - _vendor = (const char *)glGetString(GL_VENDOR); - _version = (const char *)glGetString(GL_VERSION); + _vendor = (const char *)glGetString(GL_VENDOR); + _version = (const char *)glGetString(GL_VERSION); CC_LOG_INFO("GLES2 device initialized."); CC_LOG_INFO("RENDERER: %s", _renderer.c_str()); @@ -170,15 +174,6 @@ bool GLES2Device::initialize(const DeviceInfo &info) { CC_LOG_INFO("USE_VAO: %s", _useVAO ? "true" : "false"); CC_LOG_INFO("COMPRESSED_FORMATS: %s", compressedFmts.c_str()); - QueueInfo queueInfo; - queueInfo.type = QueueType::GRAPHICS; - _queue = createQueue(queueInfo); - - CommandBufferInfo cmdBuffInfo; - cmdBuffInfo.type = CommandBufferType::PRIMARY; - cmdBuffInfo.queue = _queue; - _cmdBuff = createCommandBuffer(cmdBuffInfo); - glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, (GLint *)&_caps.maxVertexAttributes); glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, (GLint *)&_caps.maxVertexUniformVectors); glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, (GLint *)&_caps.maxFragmentUniformVectors); @@ -188,24 +183,24 @@ bool GLES2Device::initialize(const DeviceInfo &info) { glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, (GLint *)&_caps.maxCubeMapTextureSize); glGetIntegerv(GL_DEPTH_BITS, (GLint *)&_caps.depthBits); glGetIntegerv(GL_STENCIL_BITS, (GLint *)&_caps.stencilBits); - _caps.uboOffsetAlignment = 1u; _gpuStateCache->initialize(_caps.maxTextureUnits, _caps.maxVertexAttributes); return true; } -void GLES2Device::destroy() { - CC_SAFE_DESTROY(_queue); - CC_SAFE_DESTROY(_cmdBuff); +void GLES2Device::doDestroy() { CC_SAFE_DELETE(_gpuStagingBufferPool); CC_SAFE_DELETE(_gpuStateCache); + + CC_SAFE_DESTROY(_cmdBuff); + CC_SAFE_DESTROY(_queue); CC_SAFE_DESTROY(_deviceContext); CC_SAFE_DESTROY(_renderContext); } void GLES2Device::resize(uint width, uint height) { - _width = width; + _width = width; _height = height; } @@ -215,9 +210,9 @@ void GLES2Device::acquire() { void GLES2Device::present() { GLES2Queue *queue = (GLES2Queue *)_queue; - _numDrawCalls = queue->_numDrawCalls; - _numInstances = queue->_numInstances; - _numTriangles = queue->_numTriangles; + _numDrawCalls = queue->_numDrawCalls; + _numInstances = queue->_numInstances; + _numTriangles = queue->_numTriangles; _context->present(); @@ -241,9 +236,9 @@ void GLES2Device::bindDeviceContext(bool bound) { if (!_deviceContext) { ContextInfo ctxInfo; ctxInfo.windowHandle = _windowHandle; - ctxInfo.sharedCtx = _renderContext; + ctxInfo.sharedCtx = _renderContext; - _deviceContext = CC_NEW(GLES2Context(this)); + _deviceContext = CC_NEW(GLES2Context); _deviceContext->initialize(ctxInfo); } _deviceContext->MakeCurrent(bound); @@ -255,65 +250,65 @@ void GLES2Device::bindDeviceContext(bool bound) { } } -CommandBuffer *GLES2Device::doCreateCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { - if (hasAgent || info.type == CommandBufferType::PRIMARY) return CC_NEW(GLES2PrimaryCommandBuffer(this)); - return CC_NEW(GLES2CommandBuffer(this)); +CommandBuffer *GLES2Device::createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { + if (hasAgent || info.type == CommandBufferType::PRIMARY) return CC_NEW(GLES2PrimaryCommandBuffer); + return CC_NEW(GLES2CommandBuffer); } Queue *GLES2Device::createQueue() { - return CC_NEW(GLES2Queue(this)); + return CC_NEW(GLES2Queue); } Buffer *GLES2Device::createBuffer() { - return CC_NEW(GLES2Buffer(this)); + return CC_NEW(GLES2Buffer); } Texture *GLES2Device::createTexture() { - return CC_NEW(GLES2Texture(this)); + return CC_NEW(GLES2Texture); } Sampler *GLES2Device::createSampler() { - return CC_NEW(GLES2Sampler(this)); + return CC_NEW(GLES2Sampler); } Shader *GLES2Device::createShader() { - return CC_NEW(GLES2Shader(this)); + return CC_NEW(GLES2Shader); } InputAssembler *GLES2Device::createInputAssembler() { - return CC_NEW(GLES2InputAssembler(this)); + return CC_NEW(GLES2InputAssembler); } RenderPass *GLES2Device::createRenderPass() { - return CC_NEW(GLES2RenderPass(this)); + return CC_NEW(GLES2RenderPass); } Framebuffer *GLES2Device::createFramebuffer() { - return CC_NEW(GLES2Framebuffer(this)); + return CC_NEW(GLES2Framebuffer); } DescriptorSet *GLES2Device::createDescriptorSet() { - return CC_NEW(GLES2DescriptorSet(this)); + return CC_NEW(GLES2DescriptorSet); } DescriptorSetLayout *GLES2Device::createDescriptorSetLayout() { - return CC_NEW(GLES2DescriptorSetLayout(this)); + return CC_NEW(GLES2DescriptorSetLayout); } PipelineLayout *GLES2Device::createPipelineLayout() { - return CC_NEW(GLES2PipelineLayout(this)); + return CC_NEW(GLES2PipelineLayout); } PipelineState *GLES2Device::createPipelineState() { - return CC_NEW(GLES2PipelineState(this)); + return CC_NEW(GLES2PipelineState); } GlobalBarrier *GLES2Device::createGlobalBarrier() { - return CC_NEW(GlobalBarrier(this)); + return CC_NEW(GlobalBarrier); } TextureBarrier *GLES2Device::createTextureBarrier() { - return CC_NEW(TextureBarrier(this)); + return CC_NEW(TextureBarrier); } void GLES2Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { diff --git a/native/cocos/renderer/gfx-gles2/GLES2Device.h b/native/cocos/renderer/gfx-gles2/GLES2Device.h index cc620e3dfa..bf763d0bd5 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Device.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Device.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_DEVICE_H_ -#define CC_GFXGLES2_DEVICE_H_ +#pragma once #include "gfx-base/GFXDevice.h" @@ -45,8 +44,9 @@ class GLES2GPUStagingBufferPool; class CC_GLES2_API GLES2Device final : public Device { public: - GLES2Device(); - ~GLES2Device(); + static GLES2Device *getInstance(); + + ~GLES2Device() override; using Device::copyBuffersToTexture; using Device::createBuffer; @@ -65,11 +65,9 @@ public: using Device::createTexture; using Device::createTextureBarrier; - virtual bool initialize(const DeviceInfo &info) override; - virtual void destroy() override; - virtual void resize(uint width, uint height) override; - virtual void acquire() override; - virtual void present() override; + void resize(uint width, uint height) override; + void acquire() override; + void present() override; CC_INLINE bool useVAO() const { return _useVAO; } CC_INLINE bool useDrawInstanced() const { return _useDrawInstanced; } @@ -91,27 +89,35 @@ public: CC_INLINE uint getThreadID() const { return _threadID; } protected: - virtual CommandBuffer * doCreateCommandBuffer(const CommandBufferInfo &info, bool hasAgent) override; - virtual Queue * createQueue() override; - virtual Buffer * createBuffer() override; - virtual Texture * createTexture() override; - virtual Sampler * createSampler() override; - virtual Shader * createShader() override; - virtual InputAssembler * createInputAssembler() override; - virtual RenderPass * createRenderPass() override; - virtual Framebuffer * createFramebuffer() override; - virtual DescriptorSet * createDescriptorSet() override; - virtual DescriptorSetLayout *createDescriptorSetLayout() override; - virtual PipelineLayout * createPipelineLayout() override; - virtual PipelineState * createPipelineState() override; - virtual GlobalBarrier * createGlobalBarrier() override; - virtual TextureBarrier * createTextureBarrier() override; - virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; + static GLES2Device * _instance; - virtual void bindRenderContext(bool bound) override; - virtual void bindDeviceContext(bool bound) override; + friend class DeviceCreator; + friend class GLES2Context; + + GLES2Device(); + + bool doInit(const DeviceInfo &info) override; + void doDestroy() override; + CommandBuffer * createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) override; + Queue * createQueue() override; + Buffer * createBuffer() override; + Texture * createTexture() override; + Sampler * createSampler() override; + Shader * createShader() override; + InputAssembler * createInputAssembler() override; + RenderPass * createRenderPass() override; + Framebuffer * createFramebuffer() override; + DescriptorSet * createDescriptorSet() override; + DescriptorSetLayout *createDescriptorSetLayout() override; + PipelineLayout * createPipelineLayout() override; + PipelineState * createPipelineState() override; + GlobalBarrier * createGlobalBarrier() override; + TextureBarrier * createTextureBarrier() override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; + + void bindRenderContext(bool bound) override; + void bindDeviceContext(bool bound) override; -private: bool checkForETC2() const; GLES2Context * _renderContext = nullptr; @@ -131,5 +137,3 @@ private: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp index e0ac2e204f..a2d488fb33 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.cpp @@ -24,27 +24,24 @@ ****************************************************************************/ #include "GLES2Std.h" + +#include "GLES2Commands.h" +#include "GLES2Device.h" #include "GLES2Framebuffer.h" #include "GLES2RenderPass.h" -#include "GLES2Commands.h" #include "GLES2Texture.h" namespace cc { namespace gfx { -GLES2Framebuffer::GLES2Framebuffer(Device *device) -: Framebuffer(device) { +GLES2Framebuffer::GLES2Framebuffer() +: Framebuffer() { } GLES2Framebuffer::~GLES2Framebuffer() { } -bool GLES2Framebuffer::initialize(const FramebufferInfo &info) { - - _renderPass = info.renderPass; - _colorTextures = info.colorTextures; - _depthStencilTexture = info.depthStencilTexture; - +void GLES2Framebuffer::doInit(const FramebufferInfo &info) { if (info.depthStencilMipmapLevel != 0) { CC_LOG_WARNING("Mipmap level of depth stencil attachment should be 0 in GLES2. Convert to 0."); } @@ -58,7 +55,7 @@ bool GLES2Framebuffer::initialize(const FramebufferInfo &info) { } } - _gpuFBO = CC_NEW(GLES2GPUFramebuffer); + _gpuFBO = CC_NEW(GLES2GPUFramebuffer); _gpuFBO->gpuRenderPass = ((GLES2RenderPass *)_renderPass)->gpuRenderPass(); _gpuFBO->gpuColorTextures.resize(_colorTextures.size()); @@ -73,14 +70,12 @@ bool GLES2Framebuffer::initialize(const FramebufferInfo &info) { _gpuFBO->gpuDepthStencilTexture = ((GLES2Texture *)_depthStencilTexture)->gpuTexture(); } - GLES2CmdFuncCreateFramebuffer((GLES2Device *)_device, _gpuFBO); - - return true; + GLES2CmdFuncCreateFramebuffer(GLES2Device::getInstance(), _gpuFBO); } -void GLES2Framebuffer::destroy() { +void GLES2Framebuffer::doDestroy() { if (_gpuFBO) { - GLES2CmdFuncDestroyFramebuffer((GLES2Device *)_device, _gpuFBO); + GLES2CmdFuncDestroyFramebuffer(GLES2Device::getInstance(), _gpuFBO); CC_DELETE(_gpuFBO); _gpuFBO = nullptr; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.h b/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.h index 900b8cc4af..c65ad8887d 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Framebuffer.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_FRAMEBUFFER_H_ -#define CC_GFXGLES2_FRAMEBUFFER_H_ +#pragma once #include "gfx-base/GFXFramebuffer.h" @@ -35,20 +34,17 @@ class GLES2GPUFramebuffer; class CC_GLES2_API GLES2Framebuffer final : public Framebuffer { public: - GLES2Framebuffer(Device *device); + GLES2Framebuffer(); ~GLES2Framebuffer(); -public: - virtual bool initialize(const FramebufferInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES2GPUFramebuffer *gpuFBO() const { return _gpuFBO; } -private: +protected: + void doInit(const FramebufferInfo &info) override; + void doDestroy() override; + GLES2GPUFramebuffer *_gpuFBO = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h b/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h index 74e16e0416..b9d38987de 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h +++ b/native/cocos/renderer/gfx-gles2/GLES2GPUObjects.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_GPU_OBJECTS_H_ -#define CC_GFXGLES2_GPU_OBJECTS_H_ +#pragma once #include "gfx-base/GFXDef.h" #include "GLES2Wrangler.h" @@ -408,5 +407,3 @@ private: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cpp b/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cpp index cd51f7d253..a4b0bad0fc 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.cpp @@ -24,41 +24,28 @@ ****************************************************************************/ #include "GLES2Std.h" -#include "GLES2InputAssembler.h" -#include "GLES2Commands.h" + #include "GLES2Buffer.h" +#include "GLES2Commands.h" +#include "GLES2Device.h" +#include "GLES2InputAssembler.h" namespace cc { namespace gfx { -GLES2InputAssembler::GLES2InputAssembler(Device *device) -: InputAssembler(device) { +GLES2InputAssembler::GLES2InputAssembler() +: InputAssembler() { } GLES2InputAssembler::~GLES2InputAssembler() { } -bool GLES2InputAssembler::initialize(const InputAssemblerInfo &info) { - - _attributes = info.attributes; - _vertexBuffers = info.vertexBuffers; - _indexBuffer = info.indexBuffer; - _indirectBuffer = info.indirectBuffer; - - if (_indexBuffer) { - _indexCount = _indexBuffer->getCount(); - _firstIndex = 0; - } else if (_vertexBuffers.size()) { - _vertexCount = _vertexBuffers[0]->getCount(); - _firstVertex = 0; - _vertexOffset = 0; - } - - _gpuInputAssembler = CC_NEW(GLES2GPUInputAssembler); +void GLES2InputAssembler::doInit(const InputAssemblerInfo &info) { + _gpuInputAssembler = CC_NEW(GLES2GPUInputAssembler); _gpuInputAssembler->attributes = _attributes; _gpuInputAssembler->gpuVertexBuffers.resize(_vertexBuffers.size()); for (size_t i = 0; i < _gpuInputAssembler->gpuVertexBuffers.size(); ++i) { - GLES2Buffer *vb = (GLES2Buffer *)_vertexBuffers[i]; + GLES2Buffer *vb = (GLES2Buffer *)_vertexBuffers[i]; _gpuInputAssembler->gpuVertexBuffers[i] = vb->gpuBuffer(); } if (info.indexBuffer) @@ -67,26 +54,23 @@ bool GLES2InputAssembler::initialize(const InputAssemblerInfo &info) { if (info.indirectBuffer) _gpuInputAssembler->gpuIndirectBuffer = static_cast(info.indirectBuffer)->gpuBuffer(); - GLES2CmdFuncCreateInputAssembler((GLES2Device *)_device, _gpuInputAssembler); - _attributesHash = computeAttributesHash(); - - return true; + GLES2CmdFuncCreateInputAssembler(GLES2Device::getInstance(), _gpuInputAssembler); } -void GLES2InputAssembler::destroy() { +void GLES2InputAssembler::doDestroy() { if (_gpuInputAssembler) { - GLES2CmdFuncDestroyInputAssembler((GLES2Device *)_device, _gpuInputAssembler); + GLES2CmdFuncDestroyInputAssembler(GLES2Device::getInstance(), _gpuInputAssembler); CC_DELETE(_gpuInputAssembler); _gpuInputAssembler = nullptr; } } void GLES2InputAssembler::ExtractCmdDraw(GLES2CmdDraw *cmd) { - cmd->drawInfo.vertexCount = _vertexCount; - cmd->drawInfo.firstVertex = _firstVertex; - cmd->drawInfo.indexCount = _indexCount; - cmd->drawInfo.firstIndex = _firstIndex; - cmd->drawInfo.vertexOffset = _vertexOffset; + cmd->drawInfo.vertexCount = _vertexCount; + cmd->drawInfo.firstVertex = _firstVertex; + cmd->drawInfo.indexCount = _indexCount; + cmd->drawInfo.firstIndex = _firstIndex; + cmd->drawInfo.vertexOffset = _vertexOffset; cmd->drawInfo.instanceCount = _instanceCount; cmd->drawInfo.firstInstance = _firstInstance; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.h b/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.h index 1d0c43cb02..f84d781ebb 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.h +++ b/native/cocos/renderer/gfx-gles2/GLES2InputAssembler.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_INPUT_ASSEMBLER_H_ -#define CC_GFXGLES2_INPUT_ASSEMBLER_H_ +#pragma once #include "gfx-base/GFXInputAssembler.h" @@ -36,22 +35,19 @@ class GLES2CmdDraw; class CC_GLES2_API GLES2InputAssembler final : public InputAssembler { public: - GLES2InputAssembler(Device *device); + GLES2InputAssembler(); ~GLES2InputAssembler(); -public: - virtual bool initialize(const InputAssemblerInfo &info) override; - virtual void destroy() override; - void ExtractCmdDraw(GLES2CmdDraw *cmd); CC_INLINE GLES2GPUInputAssembler *gpuInputAssembler() const { return _gpuInputAssembler; } -private: +protected: + void doInit(const InputAssemblerInfo &info) override; + void doDestroy() override; + GLES2GPUInputAssembler *_gpuInputAssembler = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cpp b/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cpp index e0ee0464da..9221f47af1 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.cpp @@ -32,17 +32,14 @@ namespace cc { namespace gfx { -GLES2PipelineLayout::GLES2PipelineLayout(Device *device) -: PipelineLayout(device) { +GLES2PipelineLayout::GLES2PipelineLayout() +: PipelineLayout() { } GLES2PipelineLayout::~GLES2PipelineLayout() { } -bool GLES2PipelineLayout::initialize(const PipelineLayoutInfo &info) { - - _setLayouts = info.setLayouts; - +void GLES2PipelineLayout::doInit(const PipelineLayoutInfo &info) { _gpuPipelineLayout = CC_NEW(GLES2GPUPipelineLayout); uint offset = 0u; @@ -66,11 +63,9 @@ bool GLES2PipelineLayout::initialize(const PipelineLayoutInfo &info) { _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); _gpuPipelineLayout->dynamicOffsetCount = offset; _gpuPipelineLayout->dynamicOffsets.resize(offset); - - return true; } -void GLES2PipelineLayout::destroy() { +void GLES2PipelineLayout::doDestroy() { if (_gpuPipelineLayout) { CC_DELETE(_gpuPipelineLayout); diff --git a/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.h b/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.h index 3a52d20eec..8254395e74 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.h +++ b/native/cocos/renderer/gfx-gles2/GLES2PipelineLayout.h @@ -35,16 +35,15 @@ class GLES2GPUPipelineLayout; class CC_GLES2_API GLES2PipelineLayout final : public PipelineLayout { public: - GLES2PipelineLayout(Device *device); + GLES2PipelineLayout(); ~GLES2PipelineLayout(); -public: - virtual bool initialize(const PipelineLayoutInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES2GPUPipelineLayout *gpuPipelineLayout() const { return _gpuPipelineLayout; } -private: +protected: + void doInit(const PipelineLayoutInfo &info) override; + void doDestroy() override; + GLES2GPUPipelineLayout *_gpuPipelineLayout = nullptr; }; diff --git a/native/cocos/renderer/gfx-gles2/GLES2PipelineState.cpp b/native/cocos/renderer/gfx-gles2/GLES2PipelineState.cpp index 7f0ca46c01..22e62c5857 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PipelineState.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2PipelineState.cpp @@ -51,25 +51,14 @@ const GLenum GLES2Primitives[] = { GL_NONE, }; -GLES2PipelineState::GLES2PipelineState(Device *device) -: PipelineState(device) { +GLES2PipelineState::GLES2PipelineState() +: PipelineState() { } GLES2PipelineState::~GLES2PipelineState() { } -bool GLES2PipelineState::initialize(const PipelineStateInfo &info) { - _primitive = info.primitive; - _shader = info.shader; - _inputState = info.inputState; - _rasterizerState = info.rasterizerState; - _depthStencilState = info.depthStencilState; - _bindPoint = info.bindPoint; - _blendState = info.blendState; - _dynamicStates = info.dynamicStates; - _renderPass = info.renderPass; - _pipelineLayout = info.pipelineLayout; - +void GLES2PipelineState::doInit(const PipelineStateInfo &info) { _gpuPipelineState = CC_NEW(GLES2GPUPipelineState); _gpuPipelineState->glPrimitive = GLES2Primitives[(int)_primitive]; _gpuPipelineState->gpuShader = ((GLES2Shader *)_shader)->gpuShader(); @@ -84,11 +73,9 @@ bool GLES2PipelineState::initialize(const PipelineStateInfo &info) { _gpuPipelineState->dynamicStates.push_back((DynamicStateFlagBit)(1 << i)); } } - - return true; } -void GLES2PipelineState::destroy() { +void GLES2PipelineState::doDestroy() { if (_gpuPipelineState) { CC_DELETE(_gpuPipelineState); _gpuPipelineState = nullptr; diff --git a/native/cocos/renderer/gfx-gles2/GLES2PipelineState.h b/native/cocos/renderer/gfx-gles2/GLES2PipelineState.h index 2359e2aa85..2b15243fa4 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PipelineState.h +++ b/native/cocos/renderer/gfx-gles2/GLES2PipelineState.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_PIPELINE_STATE_H_ -#define CC_GFXGLES2_PIPELINE_STATE_H_ +#pragma once #include "gfx-base/GFXPipelineState.h" @@ -35,20 +34,17 @@ class GLES2GPUPipelineState; class CC_GLES2_API GLES2PipelineState final : public PipelineState { public: - GLES2PipelineState(Device *device); + GLES2PipelineState(); ~GLES2PipelineState(); -public: - virtual bool initialize(const PipelineStateInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES2GPUPipelineState *gpuPipelineState() const { return _gpuPipelineState; } -private: +protected: + void doInit(const PipelineStateInfo &info) override; + void doDestroy() override; + GLES2GPUPipelineState *_gpuPipelineState = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.cpp b/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.cpp index 5b08a4ff83..a6707bdabe 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.cpp @@ -38,8 +38,8 @@ namespace cc { namespace gfx { -GLES2PrimaryCommandBuffer::GLES2PrimaryCommandBuffer(Device *device) -: GLES2CommandBuffer(device) { +GLES2PrimaryCommandBuffer::GLES2PrimaryCommandBuffer() +: GLES2CommandBuffer() { } GLES2PrimaryCommandBuffer::~GLES2PrimaryCommandBuffer() { @@ -67,12 +67,12 @@ void GLES2PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuf GLES2GPURenderPass *gpuRenderPass = ((GLES2RenderPass *)renderPass)->gpuRenderPass(); GLES2GPUFramebuffer *gpuFramebuffer = ((GLES2Framebuffer *)fbo)->gpuFBO(); - GLES2CmdFuncBeginRenderPass((GLES2Device *)_device, gpuRenderPass, gpuFramebuffer, + GLES2CmdFuncBeginRenderPass(GLES2Device::getInstance(), gpuRenderPass, gpuFramebuffer, renderArea, gpuRenderPass->colorAttachments.size(), colors, depth, stencil); } void GLES2PrimaryCommandBuffer::endRenderPass() { - GLES2CmdFuncEndRenderPass((GLES2Device *)_device); + GLES2CmdFuncEndRenderPass(GLES2Device::getInstance()); _isInRenderPass = false; } @@ -89,7 +89,7 @@ void GLES2PrimaryCommandBuffer::draw(InputAssembler *ia) { count = std::min(count, _curDynamicOffsets[i].size()); if (count) memcpy(&dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint)); } - GLES2CmdFuncBindState((GLES2Device *)_device, _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets, dynamicOffsets, + GLES2CmdFuncBindState(GLES2Device::getInstance(), _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets, dynamicOffsets, _curViewport, _curScissor, _curLineWidth, false, _curDepthBias, _curBlendConstants, _curDepthBounds, _curStencilWriteMask, _curStencilCompareMask); _isStateInvalid = false; @@ -97,7 +97,7 @@ void GLES2PrimaryCommandBuffer::draw(InputAssembler *ia) { DrawInfo drawInfo; ia->extractDrawInfo(drawInfo); - GLES2CmdFuncDraw((GLES2Device *)_device, drawInfo); + GLES2CmdFuncDraw(GLES2Device::getInstance(), drawInfo); ++_numDrawCalls; _numInstances += ia->getInstanceCount(); @@ -127,7 +127,7 @@ void GLES2PrimaryCommandBuffer::updateBuffer(Buffer *buff, const void *data, uin GLES2GPUBuffer *gpuBuffer = ((GLES2Buffer *)buff)->gpuBuffer(); if (gpuBuffer) { - GLES2CmdFuncUpdateBuffer((GLES2Device *)_device, gpuBuffer, data, 0u, size); + GLES2CmdFuncUpdateBuffer(GLES2Device::getInstance(), gpuBuffer, data, 0u, size); } } else { CC_LOG_ERROR("Command 'updateBuffer' must be recorded outside a render pass."); @@ -140,7 +140,7 @@ void GLES2PrimaryCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffe GLES2GPUTexture *gpuTexture = ((GLES2Texture *)texture)->gpuTexture(); if (gpuTexture) { - GLES2CmdFuncCopyBuffersToTexture((GLES2Device *)_device, buffers, gpuTexture, regions, count); + GLES2CmdFuncCopyBuffersToTexture(GLES2Device::getInstance(), buffers, gpuTexture, regions, count); } } else { CC_LOG_ERROR("Command 'copyBuffersToTexture' must be recorded outside a render pass."); @@ -154,7 +154,7 @@ void GLES2PrimaryCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t if (!cmdBuff->_pendingPackages.empty()) { GLES2CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); - GLES2CmdFuncExecuteCmds((GLES2Device *)_device, cmdPackage); + GLES2CmdFuncExecuteCmds(GLES2Device::getInstance(), cmdPackage); cmdBuff->_pendingPackages.pop(); cmdBuff->_freePackages.push(cmdPackage); diff --git a/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.h b/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.h index c52e3ac48b..e38010049d 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.h +++ b/native/cocos/renderer/gfx-gles2/GLES2PrimaryCommandBuffer.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_PRIMARY_COMMAND_BUFFER_H_ -#define CC_GFXGLES2_PRIMARY_COMMAND_BUFFER_H_ +#pragma once #include "GLES2CommandBuffer.h" @@ -32,23 +31,22 @@ namespace cc { namespace gfx { class CC_GLES2_API GLES2PrimaryCommandBuffer final : public GLES2CommandBuffer { - friend class GLES2Queue; - public: - GLES2PrimaryCommandBuffer(Device *device); + GLES2PrimaryCommandBuffer(); ~GLES2PrimaryCommandBuffer(); - virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; - virtual void end() override; - virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; - virtual void endRenderPass() override; - virtual void draw(InputAssembler *ia) override; - virtual void updateBuffer(Buffer *buff, const void *data, uint size) override; - virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; - virtual void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; + void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void end() override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void endRenderPass() override; + void draw(InputAssembler *ia) 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 execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; + +protected: + friend class GLES2Queue; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2Queue.cpp b/native/cocos/renderer/gfx-gles2/GLES2Queue.cpp index dddac8ef63..9dbc1dc6a6 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Queue.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Queue.cpp @@ -24,27 +24,26 @@ ****************************************************************************/ #include "GLES2Std.h" -#include "GLES2Queue.h" -#include "GLES2Commands.h" + #include "GLES2CommandBuffer.h" +#include "GLES2Commands.h" +#include "GLES2Queue.h" +#include "GLES2Device.h" namespace cc { namespace gfx { -GLES2Queue::GLES2Queue(Device *device) -: Queue(device) { +GLES2Queue::GLES2Queue() +: Queue() { } GLES2Queue::~GLES2Queue() { } -bool GLES2Queue::initialize(const QueueInfo &info) { - _type = info.type; - - return true; +void GLES2Queue::doInit(const QueueInfo &info) { } -void GLES2Queue::destroy() { +void GLES2Queue::doDestroy() { } void GLES2Queue::submit(CommandBuffer *const *cmdBuffs, uint count) { @@ -54,7 +53,7 @@ void GLES2Queue::submit(CommandBuffer *const *cmdBuffs, uint count) { if (!cmdBuff->_pendingPackages.empty()) { GLES2CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); - GLES2CmdFuncExecuteCmds((GLES2Device *)_device, cmdPackage); + GLES2CmdFuncExecuteCmds(GLES2Device::getInstance(), cmdPackage); cmdBuff->_pendingPackages.pop(); cmdBuff->_freePackages.push(cmdPackage); diff --git a/native/cocos/renderer/gfx-gles2/GLES2Queue.h b/native/cocos/renderer/gfx-gles2/GLES2Queue.h index 9adf1bbda4..d124c01cd5 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Queue.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Queue.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_QUEUE_H_ -#define CC_GFXGLES2_QUEUE_H_ +#pragma once #include "gfx-base/GFXQueue.h" @@ -33,17 +32,17 @@ namespace gfx { class CC_GLES2_API GLES2Queue final : public Queue { public: - GLES2Queue(Device *device); + GLES2Queue(); ~GLES2Queue(); + void submit(CommandBuffer *const *cmdBuffs, uint count) override; + +protected: friend class GLES2Device; -public: - virtual bool initialize(const QueueInfo &info) override; - virtual void destroy() override; - virtual void submit(CommandBuffer *const *cmdBuffs, uint count) override; + void doInit(const QueueInfo &info) override; + void doDestroy() override; -private: uint _numDrawCalls = 0; uint _numInstances = 0; uint _numTriangles = 0; @@ -51,5 +50,3 @@ private: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2RenderPass.cpp b/native/cocos/renderer/gfx-gles2/GLES2RenderPass.cpp index 9436d08235..eec4b27392 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2RenderPass.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2RenderPass.cpp @@ -30,28 +30,20 @@ namespace cc { namespace gfx { -GLES2RenderPass::GLES2RenderPass(Device *device) -: RenderPass(device) { +GLES2RenderPass::GLES2RenderPass() +: RenderPass() { } GLES2RenderPass::~GLES2RenderPass() { } -bool GLES2RenderPass::initialize(const RenderPassInfo &info) { - - _colorAttachments = info.colorAttachments; - _depthStencilAttachment = info.depthStencilAttachment; - +void GLES2RenderPass::doInit(const RenderPassInfo &info) { _gpuRenderPass = CC_NEW(GLES2GPURenderPass); _gpuRenderPass->colorAttachments = _colorAttachments; _gpuRenderPass->depthStencilAttachment = _depthStencilAttachment; - - _hash = computeHash(); - - return true; } -void GLES2RenderPass::destroy() { +void GLES2RenderPass::doDestroy() { if (_gpuRenderPass) { CC_DELETE(_gpuRenderPass); _gpuRenderPass = nullptr; diff --git a/native/cocos/renderer/gfx-gles2/GLES2RenderPass.h b/native/cocos/renderer/gfx-gles2/GLES2RenderPass.h index b975f912c4..9665810c14 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2RenderPass.h +++ b/native/cocos/renderer/gfx-gles2/GLES2RenderPass.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_RENDER_PASS_H_ -#define CC_GFXGLES2_RENDER_PASS_H_ +#pragma once #include "gfx-base/GFXRenderPass.h" @@ -35,20 +34,17 @@ class GLES2GPURenderPass; class CC_GLES2_API GLES2RenderPass final : public RenderPass { public: - GLES2RenderPass(Device *device); + GLES2RenderPass(); ~GLES2RenderPass(); -public: - virtual bool initialize(const RenderPassInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES2GPURenderPass *gpuRenderPass() const { return _gpuRenderPass; } -private: +protected: + void doInit(const RenderPassInfo &info) override; + void doDestroy() override; + GLES2GPURenderPass *_gpuRenderPass = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2Sampler.cpp b/native/cocos/renderer/gfx-gles2/GLES2Sampler.cpp index 8ec35b74b3..5839a0da01 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Sampler.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Sampler.cpp @@ -24,47 +24,36 @@ ****************************************************************************/ #include "GLES2Std.h" -#include "GLES2Sampler.h" + #include "GLES2Commands.h" +#include "GLES2Device.h" +#include "GLES2Sampler.h" namespace cc { namespace gfx { -GLES2Sampler::GLES2Sampler(Device *device) -: Sampler(device) { +GLES2Sampler::GLES2Sampler() +: Sampler() { } GLES2Sampler::~GLES2Sampler() { } -bool GLES2Sampler::initialize(const SamplerInfo &info) { - _minFilter = info.minFilter; - _magFilter = info.magFilter; - _mipFilter = info.mipFilter; - _addressU = info.addressU; - _addressV = info.addressV; - _addressW = info.addressW; - _maxAnisotropy = info.maxAnisotropy; - _cmpFunc = info.cmpFunc; - _borderColor = info.borderColor; - _mipLODBias = info.mipLODBias; - - _gpuSampler = CC_NEW(GLES2GPUSampler); +void GLES2Sampler::doInit(const SamplerInfo &info) { + _gpuSampler = CC_NEW(GLES2GPUSampler); _gpuSampler->minFilter = _minFilter; _gpuSampler->magFilter = _magFilter; _gpuSampler->mipFilter = _mipFilter; - _gpuSampler->addressU = _addressU; - _gpuSampler->addressV = _addressV; - _gpuSampler->addressW = _addressW; + _gpuSampler->addressU = _addressU; + _gpuSampler->addressV = _addressV; + _gpuSampler->addressW = _addressW; - GLES2CmdFuncCreateSampler((GLES2Device *)_device, _gpuSampler); - - return true; + GLES2CmdFuncCreateSampler(GLES2Device::getInstance(), _gpuSampler); } -void GLES2Sampler::destroy() { +void GLES2Sampler::doDestroy() { if (_gpuSampler) { - GLES2CmdFuncDestroySampler((GLES2Device *)_device, _gpuSampler); + GLES2CmdFuncDestroySampler(GLES2Device::getInstance(), _gpuSampler); CC_DELETE(_gpuSampler); _gpuSampler = nullptr; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Sampler.h b/native/cocos/renderer/gfx-gles2/GLES2Sampler.h index 425588a6be..2688d9b3df 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Sampler.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Sampler.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_SAMPLER_H_ -#define CC_GFXGLES2_SAMPLER_H_ +#pragma once #include "gfx-base/GFXSampler.h" @@ -35,16 +34,15 @@ class GLES2GPUSampler; class CC_GLES2_API GLES2Sampler final : public Sampler { public: - GLES2Sampler(Device *device); + GLES2Sampler(); ~GLES2Sampler(); -public: - virtual bool initialize(const SamplerInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES2GPUSampler *gpuSampler() const { return _gpuSampler; } -private: +protected: + void doInit(const SamplerInfo &info) override; + void doDestroy() override; + GLES2GPUSampler *_gpuSampler = nullptr; String _name; Filter _minFilter = Filter::LINEAR; @@ -63,5 +61,3 @@ private: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2Shader.cpp b/native/cocos/renderer/gfx-gles2/GLES2Shader.cpp index 95871ca288..fd3d3d6500 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Shader.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Shader.cpp @@ -24,44 +24,37 @@ ****************************************************************************/ #include "GLES2Std.h" -#include "GLES2Shader.h" + #include "GLES2Commands.h" +#include "GLES2Device.h" +#include "GLES2Shader.h" namespace cc { namespace gfx { -GLES2Shader::GLES2Shader(Device *device) -: Shader(device) { +GLES2Shader::GLES2Shader() +: Shader() { } GLES2Shader::~GLES2Shader() { } -bool GLES2Shader::initialize(const ShaderInfo &info) { - _name = info.name; - _stages = info.stages; - _attributes = info.attributes; - _blocks = info.blocks; - _buffers = info.buffers; - _samplers = info.samplers; - - _gpuShader = CC_NEW(GLES2GPUShader); - _gpuShader->name = _name; - _gpuShader->blocks = _blocks; +void GLES2Shader::doInit(const ShaderInfo &info) { + _gpuShader = CC_NEW(GLES2GPUShader); + _gpuShader->name = _name; + _gpuShader->blocks = _blocks; _gpuShader->samplers = _samplers; for (const auto &stage : _stages) { GLES2GPUShaderStage gpuShaderStage = {stage.stage, stage.source}; _gpuShader->gpuStages.emplace_back(std::move(gpuShaderStage)); } - GLES2CmdFuncCreateShader((GLES2Device *)_device, _gpuShader); - - return true; + GLES2CmdFuncCreateShader(GLES2Device::getInstance(), _gpuShader); } -void GLES2Shader::destroy() { +void GLES2Shader::doDestroy() { if (_gpuShader) { - GLES2CmdFuncDestroyShader((GLES2Device *)_device, _gpuShader); + GLES2CmdFuncDestroyShader(GLES2Device::getInstance(), _gpuShader); CC_DELETE(_gpuShader); _gpuShader = nullptr; } diff --git a/native/cocos/renderer/gfx-gles2/GLES2Shader.h b/native/cocos/renderer/gfx-gles2/GLES2Shader.h index 0ee7131377..570fb833ca 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Shader.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Shader.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_SHADER_H_ -#define CC_GFXGLES2_SHADER_H_ +#pragma once #include "gfx-base/GFXShader.h" @@ -35,20 +34,17 @@ class GLES2GPUShader; class CC_GLES2_API GLES2Shader final : public Shader { public: - GLES2Shader(Device *device); + GLES2Shader(); ~GLES2Shader(); -public: - virtual bool initialize(const ShaderInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES2GPUShader *gpuShader() const { return _gpuShader; } -private: +protected: + void doInit(const ShaderInfo &info) override; + void doDestroy() override; + GLES2GPUShader *_gpuShader = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp b/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp index c5365b7cc2..27454b53a2 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp +++ b/native/cocos/renderer/gfx-gles2/GLES2Texture.cpp @@ -32,76 +32,15 @@ namespace cc { namespace gfx { -GLES2Texture::GLES2Texture(Device *device) -: Texture(device) { +GLES2Texture::GLES2Texture() +: Texture() { } GLES2Texture::~GLES2Texture() { } -bool GLES2Texture::initialize(const TextureInfo &info) { - - _type = info.type; - _usage = info.usage; - _format = info.format; - _width = info.width; - _height = info.height; - _depth = info.depth; - _layerCount = info.layerCount; - _levelCount = info.levelCount; - _samples = info.samples; - _flags = info.flags; - _size = FormatSize(_format, _width, _height, _depth); - -#if CC_DEBUG > 0 - switch (_format) { // device feature validation - case Format::D16: - if (_device->hasFeature(Feature::FORMAT_D16)) break; - CC_LOG_ERROR("D16 texture format is not supported on this backend"); - return false; - case Format::D16S8: - if (_device->hasFeature(Feature::FORMAT_D16S8)) break; - CC_LOG_WARNING("D16S8 texture format is not supported on this backend"); - return false; - case Format::D24: - if (_device->hasFeature(Feature::FORMAT_D24)) break; - CC_LOG_WARNING("D24 texture format is not supported on this backend"); - return false; - case Format::D24S8: - if (_device->hasFeature(Feature::FORMAT_D24S8)) break; - CC_LOG_WARNING("D24S8 texture format is not supported on this backend"); - return false; - case Format::D32F: - if (_device->hasFeature(Feature::FORMAT_D32F)) break; - CC_LOG_WARNING("D32F texture format is not supported on this backend"); - return false; - case Format::D32F_S8: - if (_device->hasFeature(Feature::FORMAT_D32FS8)) break; - CC_LOG_WARNING("D32FS8 texture format is not supported on this backend"); - return false; - case Format::RGB8: - if (_device->hasFeature(Feature::FORMAT_RGB8)) break; - CC_LOG_WARNING("RGB8 texture format is not supported on this backend"); - return false; - default: - break; - } -#endif - - if (_flags & TextureFlags::BAKUP_BUFFER) { - _buffer = (uint8_t *)CC_MALLOC(_size); - if (!_buffer) { - CC_LOG_ERROR("GLES2Texture: CC_MALLOC backup buffer failed."); - return false; - } - _device->getMemoryStatus().textureSize += _size; - } - +void GLES2Texture::doInit(const TextureInfo &info) { _gpuTexture = CC_NEW(GLES2GPUTexture); - if (!_gpuTexture) { - CC_LOG_ERROR("GLES2Texture: CC_NEW GLES2GPUTexture failed."); - return false; - } _gpuTexture->type = _type; _gpuTexture->format = _format; _gpuTexture->usage = _usage; @@ -115,64 +54,26 @@ bool GLES2Texture::initialize(const TextureInfo &info) { _gpuTexture->flags = _flags; _gpuTexture->isPowerOf2 = math::IsPowerOfTwo(_width) && math::IsPowerOfTwo(_height); - GLES2CmdFuncCreateTexture((GLES2Device *)_device, _gpuTexture); - _device->getMemoryStatus().textureSize += _size; - - return true; + GLES2CmdFuncCreateTexture(GLES2Device::getInstance(), _gpuTexture); } -bool GLES2Texture::initialize(const TextureViewInfo &info) { - _isTextureView = true; - +void GLES2Texture::doInit(const TextureViewInfo &info) { CC_LOG_ERROR("GLES2 doesn't support texture view"); - return false; } -void GLES2Texture::destroy() { +void GLES2Texture::doDestroy() { if (_gpuTexture) { - GLES2CmdFuncDestroyTexture((GLES2Device *)_device, _gpuTexture); - _device->getMemoryStatus().textureSize -= _size; + GLES2CmdFuncDestroyTexture(GLES2Device::getInstance(), _gpuTexture); CC_DELETE(_gpuTexture); _gpuTexture = nullptr; } - - if (_buffer) { - CC_FREE(_buffer); - _device->getMemoryStatus().textureSize -= _size; - _buffer = nullptr; - } } -void GLES2Texture::resize(uint width, uint height) { - if (_width != width || _height != height) { - uint size = FormatSize(_format, width, height, _depth); - const uint oldSize = _size; - _width = width; - _height = height; - _size = size; - - MemoryStatus &status = _device->getMemoryStatus(); - _gpuTexture->width = _width; - _gpuTexture->height = _height; - _gpuTexture->size = _size; - GLES2CmdFuncResizeTexture((GLES2Device *)_device, _gpuTexture); - status.bufferSize -= oldSize; - status.bufferSize += _size; - - if (_buffer) { - const uint8_t *oldBuffer = _buffer; - uint8_t *buffer = (uint8_t *)CC_MALLOC(_size); - if (!buffer) { - CC_LOG_ERROR("GLES2Texture: CC_MALLOC backup buffer failed when resize the texture."); - return; - } - memcpy(buffer, oldBuffer, std::min(oldSize, size)); - _buffer = buffer; - CC_FREE(oldBuffer); - status.bufferSize -= oldSize; - status.bufferSize += _size; - } - } +void GLES2Texture::doResize(uint width, uint height) { + _gpuTexture->width = _width; + _gpuTexture->height = _height; + _gpuTexture->size = _size; + GLES2CmdFuncResizeTexture(GLES2Device::getInstance(), _gpuTexture); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles2/GLES2Texture.h b/native/cocos/renderer/gfx-gles2/GLES2Texture.h index 3379b9f53a..1ef6ad568b 100644 --- a/native/cocos/renderer/gfx-gles2/GLES2Texture.h +++ b/native/cocos/renderer/gfx-gles2/GLES2Texture.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES2_TEXTURE_H_ -#define CC_GFXGLES2_TEXTURE_H_ +#pragma once #include "gfx-base/GFXTexture.h" @@ -35,22 +34,19 @@ class GLES2GPUTexture; class CC_GLES2_API GLES2Texture final : public Texture { public: - GLES2Texture(Device *device); + GLES2Texture(); ~GLES2Texture(); -public: - virtual bool initialize(const TextureInfo &info) override; - virtual bool initialize(const TextureViewInfo &info) override; - virtual void destroy() override; - virtual void resize(uint width, uint height) override; - CC_INLINE GLES2GPUTexture *gpuTexture() const { return _gpuTexture; } -private: +protected: + void doInit(const TextureInfo &info) override; + void doInit(const TextureViewInfo &info) override; + void doDestroy() override; + void doResize(uint width, uint height) override; + GLES2GPUTexture *_gpuTexture = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GFXGLES3.h b/native/cocos/renderer/gfx-gles3/GFXGLES3.h index e358b28793..c58adb7c6e 100644 --- a/native/cocos/renderer/gfx-gles3/GFXGLES3.h +++ b/native/cocos/renderer/gfx-gles3/GFXGLES3.h @@ -23,10 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_H_ -#define CC_GFXGLES3_H_ +#pragma once #include "GLES3Std.h" #include "GLES3Device.h" - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp index 306f2be1e8..d22e8e787b 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Buffer.cpp @@ -32,26 +32,15 @@ namespace cc { namespace gfx { -GLES3Buffer::GLES3Buffer(Device *device) -: Buffer(device) { +GLES3Buffer::GLES3Buffer() +: Buffer() { } GLES3Buffer::~GLES3Buffer() { } -bool GLES3Buffer::initialize(const BufferInfo &info) { - _usage = info.usage; - _memUsage = info.memUsage; - _size = info.size; - _stride = std::max(info.stride, 1U); - _count = _size / _stride; - _flags = info.flags; - +void GLES3Buffer::doInit(const BufferInfo &info) { _gpuBuffer = CC_NEW(GLES3GPUBuffer); - if (!_gpuBuffer) { - CC_LOG_ERROR("GLES3Buffer: CC_NEW GLES3GPUBuffer failed."); - return false; - } _gpuBuffer->usage = _usage; _gpuBuffer->memUsage = _memUsage; _gpuBuffer->size = _size; @@ -62,24 +51,11 @@ bool GLES3Buffer::initialize(const BufferInfo &info) { _gpuBuffer->indirects.resize(_count); } - GLES3CmdFuncCreateBuffer((GLES3Device *)_device, _gpuBuffer); - _device->getMemoryStatus().bufferSize += _size; - - return true; + GLES3CmdFuncCreateBuffer(GLES3Device::getInstance(), _gpuBuffer); } -bool GLES3Buffer::initialize(const BufferViewInfo &info) { - - _isBufferView = true; - +void GLES3Buffer::doInit(const BufferViewInfo &info) { GLES3Buffer *buffer = (GLES3Buffer *)info.buffer; - - _usage = buffer->_usage; - _memUsage = buffer->_memUsage; - _size = _stride = info.range; - _count = 1u; - _flags = buffer->_flags; - _gpuBuffer = CC_NEW(GLES3GPUBuffer); _gpuBuffer->usage = _usage; _gpuBuffer->memUsage = _memUsage; @@ -91,42 +67,28 @@ bool GLES3Buffer::initialize(const BufferViewInfo &info) { _gpuBuffer->glOffset = info.offset; _gpuBuffer->buffer = buffer->_gpuBuffer->buffer; _gpuBuffer->indirects = buffer->_gpuBuffer->indirects; - - return true; } -void GLES3Buffer::destroy() { +void GLES3Buffer::doDestroy() { if (_gpuBuffer) { if (!_isBufferView) { - GLES3CmdFuncDestroyBuffer((GLES3Device *)_device, _gpuBuffer); - _device->getMemoryStatus().bufferSize -= _size; + GLES3CmdFuncDestroyBuffer(GLES3Device::getInstance(), _gpuBuffer); } CC_DELETE(_gpuBuffer); _gpuBuffer = nullptr; } } -void GLES3Buffer::resize(uint size) { - CCASSERT(!_isBufferView, "Cannot resize buffer views"); - - if (_size != size) { - const uint oldSize = _size; - _size = size; - _count = _size / _stride; - - MemoryStatus &status = _device->getMemoryStatus(); - _gpuBuffer->size = _size; - _gpuBuffer->count = _count; - GLES3CmdFuncResizeBuffer((GLES3Device *)_device, _gpuBuffer); - status.bufferSize -= oldSize; - status.bufferSize += _size; - } +void GLES3Buffer::doResize(uint size) { + _gpuBuffer->size = _size; + _gpuBuffer->count = _count; + GLES3CmdFuncResizeBuffer(GLES3Device::getInstance(), _gpuBuffer); } void GLES3Buffer::update(void *buffer, uint size) { CCASSERT(!_isBufferView, "Cannot update through buffer views"); - GLES3CmdFuncUpdateBuffer((GLES3Device *)_device, _gpuBuffer, buffer, 0u, size); + GLES3CmdFuncUpdateBuffer(GLES3Device::getInstance(), _gpuBuffer, buffer, 0u, size); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3Buffer.h b/native/cocos/renderer/gfx-gles3/GLES3Buffer.h index a9547e181d..bebff0394e 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Buffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Buffer.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_BUFFER_H_ -#define CC_GFXGLES3_BUFFER_H_ +#pragma once #include "gfx-base/GFXBuffer.h" @@ -35,23 +34,21 @@ class GLES3GPUBuffer; class CC_GLES3_API GLES3Buffer final : public Buffer { public: - GLES3Buffer(Device *device); + GLES3Buffer(); ~GLES3Buffer(); -public: - virtual bool initialize(const BufferInfo &info) override; - virtual bool initialize(const BufferViewInfo &info) override; - virtual void destroy() override; - virtual void resize(uint size) override; - virtual void update(void *buffer, uint size) override; + void update(void *buffer, uint size) override; CC_INLINE GLES3GPUBuffer *gpuBuffer() const { return _gpuBuffer; } -private: +protected: + void doInit(const BufferInfo &info) override; + void doInit(const BufferViewInfo &info) override; + void doDestroy() override; + void doResize(uint size) override; + GLES3GPUBuffer *_gpuBuffer = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp index 6a8a6d0123..5697047da3 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.cpp @@ -39,28 +39,23 @@ namespace cc { namespace gfx { -GLES3CommandBuffer::GLES3CommandBuffer(Device *device) -: CommandBuffer(device) { +GLES3CommandBuffer::GLES3CommandBuffer() +: CommandBuffer() { } GLES3CommandBuffer::~GLES3CommandBuffer() { } -bool GLES3CommandBuffer::initialize(const CommandBufferInfo &info) { - _type = info.type; - _queue = info.queue; - +void GLES3CommandBuffer::doInit(const CommandBufferInfo &info) { _cmdAllocator = CC_NEW(GLES3GPUCommandAllocator); _curCmdPackage = CC_NEW(GLES3CmdPackage); - size_t setCount = ((GLES3Device *)_device)->bindingMappingInfo().bufferOffsets.size(); + size_t setCount = GLES3Device::getInstance()->bindingMappingInfo().bufferOffsets.size(); _curGPUDescriptorSets.resize(setCount); _curDynamicOffsets.resize(setCount); - - return true; } -void GLES3CommandBuffer::destroy() { +void GLES3CommandBuffer::doDestroy() { _cmdAllocator->clearCmds(_curCmdPackage); CC_SAFE_DELETE(_curCmdPackage); diff --git a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h index 3ed4f1ebca..f82c86bac1 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3CommandBuffer.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_COMMAND_BUFFER_H_ -#define CC_GFXGLES3_COMMAND_BUFFER_H_ +#pragma once #include "gfx-base/GFXCommandBuffer.h" @@ -36,39 +35,39 @@ namespace gfx { class GLES3GPUCommandAllocator; class CC_GLES3_API GLES3CommandBuffer : public CommandBuffer { - friend class GLES3Queue; - public: - GLES3CommandBuffer(Device *device); + GLES3CommandBuffer(); ~GLES3CommandBuffer(); - virtual bool initialize(const CommandBufferInfo &info) override; - virtual void destroy() override; - - virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; - virtual void end() override; - virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; - virtual void endRenderPass() override; - virtual void bindPipelineState(PipelineState *pso) override; - virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; - virtual void bindInputAssembler(InputAssembler *ia) override; - virtual void setViewport(const Viewport &vp) override; - virtual void setScissor(const Rect &rect) override; - virtual void setLineWidth(float width) override; - virtual void setDepthBias(float constant, float clamp, float slope) override; - virtual void setBlendConstants(const Color &constants) override; - virtual void setDepthBound(float minBounds, float maxBounds) override; - virtual void setStencilWriteMask(StencilFace face, uint mask) override; - virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) override; - virtual void draw(InputAssembler *ia) override; - virtual void updateBuffer(Buffer *buff, const void *data, uint size) override; - virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; - virtual void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; - virtual void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; - virtual void dispatch(const DispatchInfo &info) override; - virtual void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) override; + void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void end() override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void endRenderPass() override; + void bindPipelineState(PipelineState *pso) override; + void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; + void bindInputAssembler(InputAssembler *ia) override; + void setViewport(const Viewport &vp) override; + void setScissor(const Rect &rect) override; + void setLineWidth(float width) override; + 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, int ref, uint mask) override; + void draw(InputAssembler *ia) 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 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; protected: + friend class GLES3Queue; + + void doInit(const CommandBufferInfo &info) override; + void doDestroy() override; + virtual void BindStates(); GLES3GPUCommandAllocator *_cmdAllocator = nullptr; @@ -93,5 +92,3 @@ protected: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3Commands.h b/native/cocos/renderer/gfx-gles3/GLES3Commands.h index 8c0d378e67..6de1737a7c 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Commands.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Commands.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_COMMANDS_H_ -#define CC_GFXGLES3_COMMANDS_H_ +#pragma once #include "../gfx-gles-common/GLESCommandPool.h" #include "GLES3GPUObjects.h" @@ -84,7 +83,7 @@ public: GLES3CmdBeginRenderPass() : GLESCmd(GLESCmdType::BEGIN_RENDER_PASS) {} - virtual void clear() override { + void clear() override { gpuFBO = nullptr; numClearColors = 0; } @@ -120,7 +119,7 @@ public: GLES3CmdBindStates() : GLESCmd(GLESCmdType::BIND_STATES) {} - virtual void clear() override { + void clear() override { gpuPipelineState = nullptr; gpuInputAssembler = nullptr; gpuDescriptorSets.clear(); @@ -133,7 +132,7 @@ public: DrawInfo drawInfo; GLES3CmdDraw() : GLESCmd(GLESCmdType::DRAW) {} - virtual void clear() override {} + void clear() override {} }; class GLES3CmdDispatch final : public GLESCmd { @@ -141,7 +140,7 @@ public: GLES3GPUDispatchInfo dispatchInfo; GLES3CmdDispatch() : GLESCmd(GLESCmdType::DISPATCH) {} - virtual void clear() override { + void clear() override { dispatchInfo.indirectBuffer = nullptr; dispatchInfo.indirectOffset = 0; } @@ -153,7 +152,7 @@ public: GLbitfield barriersByRegion = 0u; GLES3CmdBarrier() : GLESCmd(GLESCmdType::BARRIER) {} - virtual void clear() override { + void clear() override { barriers = 0u; barriersByRegion = 0u; } @@ -168,7 +167,7 @@ public: GLES3CmdUpdateBuffer() : GLESCmd(GLESCmdType::UPDATE_BUFFER) {} - virtual void clear() override { + void clear() override { gpuBuffer = nullptr; buffer = nullptr; } @@ -183,7 +182,7 @@ public: GLES3CmdCopyBufferToTexture() : GLESCmd(GLESCmdType::COPY_BUFFER_TO_TEXTURE) {} - virtual void clear() override { + void clear() override { gpuTexture = nullptr; regions = nullptr; count = 0u; @@ -201,7 +200,7 @@ public: GLES3CmdBlitTexture() : GLESCmd(GLESCmdType::BLIT_TEXTURE) {} - virtual void clear() override { + void clear() override { gpuTextureSrc = nullptr; gpuTextureDst = nullptr; regions = nullptr; @@ -307,5 +306,3 @@ CC_GLES3_API void GLES3CmdFuncMemoryBarrier(GLES3Device *device, GLbitfield barr } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3Context.cpp b/native/cocos/renderer/gfx-gles3/GLES3Context.cpp index a928a3c83d..46f070a351 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Context.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Context.cpp @@ -31,11 +31,9 @@ #if (CC_PLATFORM == CC_PLATFORM_ANDROID) #include "android/native_window.h" - #include "cocos/bindings/event/CustomEventTypes.h" - #include "cocos/bindings/event/EventDispatcher.h" #endif -#define FORCE_DISABLE_VALIDATION 1 +#define FORCE_DISABLE_VALIDATION 1 namespace cc { namespace gfx { @@ -86,8 +84,8 @@ void GL_APIENTRY GLES3EGLDebugProc(GLenum source, GLenum type, GLuint id, GLenum #endif -GLES3Context::GLES3Context(Device *device) -: Context(device) { +GLES3Context::GLES3Context() +: Context() { } GLES3Context::~GLES3Context() { @@ -95,20 +93,20 @@ GLES3Context::~GLES3Context() { #if (CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_MAC_OSX) -bool GLES3Context::initialize(const ContextInfo &info) { +bool GLES3Context::doInit(const ContextInfo &info) { - _vsyncMode = info.vsyncMode; + _vsyncMode = info.vsyncMode; _windowHandle = info.windowHandle; ////////////////////////////////////////////////////////////////////////// - if (!gles3wInit()) { - return false; - } - if (!info.sharedCtx) { + if (!gles3wInit()) { + return false; + } + _isPrimaryContex = true; - _windowHandle = info.windowHandle; + _windowHandle = info.windowHandle; #if (CC_PLATFORM == CC_PLATFORM_WINDOWS) _nativeDisplay = (NativeDisplayType)GetDC((HWND)_windowHandle); @@ -141,7 +139,7 @@ bool GLES3Context::initialize(const ContextInfo &info) { // rather than any other API (such as OpenVG). EGL_CHECK(eglBindAPI(EGL_OPENGL_ES_API)); - _colorFmt = Format::RGBA8; + _colorFmt = Format::RGBA8; _depthStencilFmt = Format::D24S8; const EGLint attribs[] = { @@ -171,7 +169,7 @@ bool GLES3Context::initialize(const ContextInfo &info) { return false; } - EGLint depth = attribs[13]; + EGLint depth = attribs[13]; EGLint stencil = attribs[15]; CC_LOG_INFO("Setup EGLConfig: depth [%d] stencil [%d]", depth, stencil); @@ -208,8 +206,8 @@ bool GLES3Context::initialize(const ContextInfo &info) { return false; } - uint width = _device->getWidth(); - uint height = _device->getHeight(); + uint width = GLES3Device::getInstance()->getWidth(); + uint height = GLES3Device::getInstance()->getHeight(); ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, nFmt); #endif @@ -228,7 +226,7 @@ bool GLES3Context::initialize(const ContextInfo &info) { _majorVersion = 3; _minorVersion = 0; EGLint ctxAttribs[32]; - uint n = 0; + uint n = 0; bool hasKHRCreateCtx = CheckExtension(CC_TOSTR(EGL_KHR_create_context)); if (hasKHRCreateCtx) { @@ -236,7 +234,7 @@ bool GLES3Context::initialize(const ContextInfo &info) { #if (CC_PLATFORM == CC_PLATFORM_MAC_OSX) m = 0; // Mac OpenGL doesn't really support ES 3.1+ features #endif - n = 0; + n = 0; ctxAttribs[n++] = EGL_CONTEXT_MAJOR_VERSION_KHR; ctxAttribs[n++] = _majorVersion; ctxAttribs[n++] = EGL_CONTEXT_MINOR_VERSION_KHR; @@ -257,7 +255,7 @@ bool GLES3Context::initialize(const ContextInfo &info) { } else { ctxAttribs[n++] = EGL_CONTEXT_CLIENT_VERSION; ctxAttribs[n++] = _majorVersion; - ctxAttribs[n] = EGL_NONE; + ctxAttribs[n] = EGL_NONE; EGL_CHECK(_eglContext = eglCreateContext(_eglDisplay, _eglConfig, NULL, ctxAttribs)); } @@ -268,55 +266,20 @@ bool GLES3Context::initialize(const ContextInfo &info) { _eglSharedContext = _eglContext; - #if (CC_PLATFORM == CC_PLATFORM_ANDROID) - EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [=](const CustomEvent &) -> void { - if (_eglSurface != EGL_NO_SURFACE) { - eglDestroySurface(_eglDisplay, _eglSurface); - _eglSurface = EGL_NO_SURFACE; - } - }); - - EventDispatcher::addCustomEventListener(EVENT_RECREATE_WINDOW, [=](const CustomEvent &event) -> void { - _windowHandle = (uintptr_t)event.args->ptrVal; - - EGLint nFmt; - if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { - CC_LOG_ERROR("Getting configuration attributes failed."); - return; - } - uint width = _device->getWidth(); - uint height = _device->getHeight(); - ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, nFmt); - - EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, (EGLNativeWindowType)_windowHandle, NULL)); - if (_eglSurface == EGL_NO_SURFACE) { - CC_LOG_ERROR("Recreate window surface failed."); - return; - } - - ((GLES3Context *)_device->getContext())->MakeCurrent(); - ((GLES3Device *)_device)->stateCache()->reset(); - }); - #endif - - if (!gles3wInit()) { - return false; - } - } else { GLES3Context *sharedCtx = (GLES3Context *)info.sharedCtx; - _majorVersion = sharedCtx->major_ver(); - _minorVersion = sharedCtx->minor_ver(); - _nativeDisplay = sharedCtx->native_display(); - _eglDisplay = sharedCtx->egl_display(); - _eglConfig = sharedCtx->egl_config(); + _majorVersion = sharedCtx->major_ver(); + _minorVersion = sharedCtx->minor_ver(); + _nativeDisplay = sharedCtx->native_display(); + _eglDisplay = sharedCtx->egl_display(); + _eglConfig = sharedCtx->egl_config(); _eglSharedContext = sharedCtx->egl_shared_ctx(); - _eglSurface = sharedCtx->egl_surface(); - _colorFmt = sharedCtx->getColorFormat(); - _depthStencilFmt = sharedCtx->getDepthStencilFormat(); - _extensions = sharedCtx->_extensions; - _isInitialized = sharedCtx->_isInitialized; + _eglSurface = sharedCtx->egl_surface(); + _colorFmt = sharedCtx->getColorFormat(); + _depthStencilFmt = sharedCtx->getDepthStencilFormat(); + _extensions = sharedCtx->_extensions; + _isInitialized = sharedCtx->_isInitialized; bool hasKHRCreateCtx = CheckExtension(CC_TOSTR(EGL_KHR_create_context)); if (!hasKHRCreateCtx) { @@ -325,7 +288,7 @@ bool GLES3Context::initialize(const ContextInfo &info) { } EGLint ctxAttribs[32]; - uint n = 0; + uint n = 0; if (hasKHRCreateCtx) { ctxAttribs[n++] = EGL_CONTEXT_MAJOR_VERSION_KHR; @@ -354,7 +317,7 @@ bool GLES3Context::initialize(const ContextInfo &info) { return true; } -void GLES3Context::destroy() { +void GLES3Context::doDestroy() { EGL_CHECK(eglMakeCurrent(_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); if (_eglContext != EGL_NO_CONTEXT) { @@ -362,27 +325,62 @@ void GLES3Context::destroy() { _eglContext = EGL_NO_CONTEXT; } - if (_isPrimaryContex && _eglSurface != EGL_NO_SURFACE) { - EGL_CHECK(eglDestroySurface(_eglDisplay, _eglSurface)); - _eglSurface = EGL_NO_SURFACE; - } + if (_isPrimaryContex) { + if (_eglSurface != EGL_NO_SURFACE) { + EGL_CHECK(eglDestroySurface(_eglDisplay, _eglSurface)); + _eglSurface = EGL_NO_SURFACE; + } - if (_eglDisplay != EGL_NO_DISPLAY) { - EGL_CHECK(eglTerminate(_eglDisplay)); - _eglDisplay = EGL_NO_DISPLAY; - } + if (_eglDisplay != EGL_NO_DISPLAY) { + EGL_CHECK(eglTerminate(_eglDisplay)); + _eglDisplay = EGL_NO_DISPLAY; + } #if (CC_PLATFORM == CC_PLATFORM_WINDOWS) - if (_isPrimaryContex && _nativeDisplay) { - ReleaseDC((HWND)_windowHandle, _nativeDisplay); - } + if (_nativeDisplay) { + ReleaseDC((HWND)_windowHandle, _nativeDisplay); + } #endif + } _isPrimaryContex = false; - _windowHandle = 0; - _nativeDisplay = 0; - _vsyncMode = VsyncMode::OFF; - _isInitialized = false; + _windowHandle = 0; + _nativeDisplay = 0; + _vsyncMode = VsyncMode::OFF; + _isInitialized = false; +} + +void GLES3Context::releaseSurface(uintptr_t windowHandle) { + #if (CC_PLATFORM == CC_PLATFORM_ANDROID) + if (_eglSurface != EGL_NO_SURFACE) { + eglDestroySurface(_eglDisplay, _eglSurface); + _eglSurface = EGL_NO_SURFACE; + } + #endif +} + +void GLES3Context::acquireSurface(uintptr_t windowHandle) { + #if (CC_PLATFORM == CC_PLATFORM_ANDROID) + _windowHandle = windowHandle; + + EGLint nFmt; + if (eglGetConfigAttrib(_eglDisplay, _eglConfig, EGL_NATIVE_VISUAL_ID, &nFmt) == EGL_FALSE) { + CC_LOG_ERROR("Getting configuration attributes failed."); + return; + } + uint width = GLES3Device::getInstance()->getWidth(); + uint height = GLES3Device::getInstance()->getHeight(); + ANativeWindow_setBuffersGeometry((ANativeWindow *)_windowHandle, width, height, nFmt); + + EGL_CHECK(_eglSurface = eglCreateWindowSurface(_eglDisplay, _eglConfig, (EGLNativeWindowType)_windowHandle, NULL)); + if (_eglSurface == EGL_NO_SURFACE) { + CC_LOG_ERROR("Recreate window surface failed."); + return; + } + + ((GLES3Context *)GLES3Device::getInstance()->getContext())->MakeCurrent(); + GLES3Device::getInstance()->stateCache()->reset(); + #endif } bool GLES3Context::MakeCurrentImpl(bool bound) { diff --git a/native/cocos/renderer/gfx-gles3/GLES3Context.h b/native/cocos/renderer/gfx-gles3/GLES3Context.h index 00f87c6d80..c4e6ba25b1 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Context.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Context.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_EGL_CONTEXT_H_ -#define CC_GFXGLES3_EGL_CONTEXT_H_ +#pragma once #include "gfx-base/GFXContext.h" @@ -35,13 +34,10 @@ namespace gfx { class CC_GLES3_API GLES3Context final : public Context { public: - GLES3Context(Device *device); + GLES3Context(); ~GLES3Context(); -public: - virtual bool initialize(const ContextInfo &info) override; - virtual void destroy() override; - virtual void present() override; + void present() override; bool MakeCurrent(bool bound); bool CheckExtension(const String &extension) const; @@ -49,47 +45,52 @@ public: #if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) CC_INLINE intptr_t eagl_context() const { return _eaglContext; } CC_INLINE intptr_t eagl_shared_ctx() const { return _eaglSharedContext; } - CC_INLINE uint getDefaultFramebuffer() const { return _defaultFBO; } + CC_INLINE uint getDefaultFramebuffer() const { return _defaultFBO; } #else CC_INLINE NativeDisplayType native_display() const { return _nativeDisplay; } - CC_INLINE EGLDisplay egl_display() const { return _eglDisplay; } - CC_INLINE EGLConfig egl_config() const { return _eglConfig; } - CC_INLINE EGLSurface egl_surface() const { return _eglSurface; } - CC_INLINE EGLContext egl_context() const { return _eglContext; } - CC_INLINE EGLContext egl_shared_ctx() const { return _eglSharedContext; } + CC_INLINE EGLDisplay egl_display() const { return _eglDisplay; } + CC_INLINE EGLConfig egl_config() const { return _eglConfig; } + CC_INLINE EGLSurface egl_surface() const { return _eglSurface; } + CC_INLINE EGLContext egl_context() const { return _eglContext; } + CC_INLINE EGLContext egl_shared_ctx() const { return _eglSharedContext; } #endif CC_INLINE bool MakeCurrent() { return MakeCurrent(true); } - CC_INLINE int major_ver() const { return _majorVersion; } - CC_INLINE int minor_ver() const { return _minorVersion; } + CC_INLINE int major_ver() const { return _majorVersion; } + CC_INLINE int minor_ver() const { return _minorVersion; } -private: + void releaseSurface(uintptr_t windowHandle); + void acquireSurface(uintptr_t windowHandle); + +protected: bool MakeCurrentImpl(bool bound); #if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) bool createCustomFrameBuffer(); - void destroyCustomFrameBuffer(); + void doDestroyCustomFrameBuffer(); #endif -private: +protected: + bool doInit(const ContextInfo &info) override; + void doDestroy() override; + bool _isPrimaryContex = false; #if (CC_PLATFORM == CC_PLATFORM_MAC_IOS) - intptr_t _eaglContext = 0; + intptr_t _eaglContext = 0; intptr_t _eaglSharedContext = 0; // iOS needs to created frame buffer and attach color/depth/stencil buffer. - uint _defaultFBO = 0; - uint _defaultColorBuffer = 0; + uint _defaultFBO = 0; + uint _defaultColorBuffer = 0; uint _defaultDepthStencilBuffer = 0; #else - NativeDisplayType _nativeDisplay = 0; - EGLDisplay _eglDisplay = EGL_NO_DISPLAY; - EGLConfig _eglConfig = EGL_NO_CONFIG_KHR; - EGLSurface _eglSurface = EGL_NO_SURFACE; - EGLContext _eglContext = EGL_NO_CONTEXT; - EGLContext _eglSharedContext = EGL_NO_CONTEXT; -#endif - int _majorVersion = 0; - int _minorVersion = 0; - StringArray _extensions; - bool _isInitialized = false; + NativeDisplayType _nativeDisplay = 0; + EGLDisplay _eglDisplay = EGL_NO_DISPLAY; + EGLConfig _eglConfig = EGL_NO_CONFIG_KHR; + EGLSurface _eglSurface = EGL_NO_SURFACE; + EGLContext _eglContext = EGL_NO_CONTEXT; + EGLContext _eglSharedContext = EGL_NO_CONTEXT; + int _majorVersion = 0; + int _minorVersion = 0; + StringArray _extensions; + bool _isInitialized = false; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3Context.mm b/native/cocos/renderer/gfx-gles3/GLES3Context.mm index 3741102279..479777b464 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Context.mm +++ b/native/cocos/renderer/gfx-gles3/GLES3Context.mm @@ -33,7 +33,7 @@ namespace cc { namespace gfx { -bool GLES3Context::initialize(const ContextInfo &info) { +void GLES3Context::doInit(const ContextInfo &info) { _vsyncMode = info.vsyncMode; _windowHandle = info.windowHandle; @@ -189,7 +189,7 @@ void GLES3Context::destroyCustomFrameBuffer() { } } -void GLES3Context::destroy() { +void GLES3Context::doDestroy() { destroyCustomFrameBuffer(); if (_eaglContext) { diff --git a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp index a18767c067..867485dcc8 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.cpp @@ -35,25 +35,18 @@ namespace cc { namespace gfx { -GLES3DescriptorSet::GLES3DescriptorSet(Device *device) -: DescriptorSet(device) { +GLES3DescriptorSet::GLES3DescriptorSet() +: DescriptorSet() { } GLES3DescriptorSet::~GLES3DescriptorSet() { } -bool GLES3DescriptorSet::initialize(const DescriptorSetInfo &info) { - - _layout = info.layout; - +void GLES3DescriptorSet::doInit(const DescriptorSetInfo &info) { const GLES3GPUDescriptorSetLayout *gpuDescriptorSetLayout = ((GLES3DescriptorSetLayout *)_layout)->gpuDescriptorSetLayout(); const size_t descriptorCount = gpuDescriptorSetLayout->descriptorCount; const size_t bindingCount = gpuDescriptorSetLayout->bindings.size(); - _buffers.resize(descriptorCount); - _textures.resize(descriptorCount); - _samplers.resize(descriptorCount); - _gpuDescriptorSet = CC_NEW(GLES3GPUDescriptorSet); _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount); for (size_t i = 0u, k = 0u; i < bindingCount; i++) { @@ -64,19 +57,13 @@ bool GLES3DescriptorSet::initialize(const DescriptorSetInfo &info) { } _gpuDescriptorSet->descriptorIndices = &gpuDescriptorSetLayout->descriptorIndices; - - return true; } -void GLES3DescriptorSet::destroy() { +void GLES3DescriptorSet::doDestroy() { if (_gpuDescriptorSet) { CC_DELETE(_gpuDescriptorSet); _gpuDescriptorSet = nullptr; } - // do remember to clear these or else it might not be properly updated when reused - _buffers.clear(); - _textures.clear(); - _samplers.clear(); } void GLES3DescriptorSet::update() { diff --git a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.h b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.h index 0f8792be85..2bb082e9b7 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.h +++ b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSet.h @@ -35,17 +35,17 @@ class GLES3GPUDescriptorSet; class CC_GLES3_API GLES3DescriptorSet final : public DescriptorSet { public: - GLES3DescriptorSet(Device *device); + GLES3DescriptorSet(); ~GLES3DescriptorSet(); -public: - virtual bool initialize(const DescriptorSetInfo &info) override; - virtual void destroy() override; - virtual void update() override; + void update() override; CC_INLINE GLES3GPUDescriptorSet *gpuDescriptorSet() const { return _gpuDescriptorSet; } -private: +protected: + void doInit(const DescriptorSetInfo &info) override; + void doDestroy() override; + GLES3GPUDescriptorSet *_gpuDescriptorSet = nullptr; }; diff --git a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cpp b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cpp index a752a86ad9..f95a406a95 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.cpp @@ -31,45 +31,21 @@ namespace cc { namespace gfx { -GLES3DescriptorSetLayout::GLES3DescriptorSetLayout(Device *device) -: DescriptorSetLayout(device) { +GLES3DescriptorSetLayout::GLES3DescriptorSetLayout() +: DescriptorSetLayout() { } GLES3DescriptorSetLayout::~GLES3DescriptorSetLayout() { } -bool GLES3DescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { - - _bindings = info.bindings; - size_t bindingCount = _bindings.size(); - _descriptorCount = 0u; - - if (bindingCount) { - uint maxBinding = 0u; - vector flattenedIndices(bindingCount); - for (uint i = 0u; i < bindingCount; i++) { - const DescriptorSetLayoutBinding &binding = _bindings[i]; - flattenedIndices[i] = _descriptorCount; - _descriptorCount += binding.count; - if (binding.binding > maxBinding) maxBinding = binding.binding; - } - - _bindingIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); - _descriptorIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); - for (uint i = 0u; i < bindingCount; i++) { - const DescriptorSetLayoutBinding &binding = _bindings[i]; - _bindingIndices[binding.binding] = i; - _descriptorIndices[binding.binding] = flattenedIndices[i]; - } - } - +void GLES3DescriptorSetLayout::doInit(const DescriptorSetLayoutInfo &info) { _gpuDescriptorSetLayout = CC_NEW(GLES3GPUDescriptorSetLayout); _gpuDescriptorSetLayout->descriptorCount = _descriptorCount; _gpuDescriptorSetLayout->bindingIndices = _bindingIndices; _gpuDescriptorSetLayout->descriptorIndices = _descriptorIndices; _gpuDescriptorSetLayout->bindings = _bindings; - for (uint i = 0u; i < bindingCount; i++) { + for (uint i = 0u; i < _bindings.size(); i++) { const DescriptorSetLayoutBinding &binding = _bindings[i]; if (binding.descriptorType & DESCRIPTOR_DYNAMIC_TYPE) { for (uint j = 0u; j < binding.count; j++) { @@ -77,10 +53,9 @@ bool GLES3DescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { } } } - return true; } -void GLES3DescriptorSetLayout::destroy() { +void GLES3DescriptorSetLayout::doDestroy() { if (_gpuDescriptorSetLayout) { CC_DELETE(_gpuDescriptorSetLayout); _gpuDescriptorSetLayout = nullptr; diff --git a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.h b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.h index 0a39346561..53ea3ca0c6 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.h +++ b/native/cocos/renderer/gfx-gles3/GLES3DescriptorSetLayout.h @@ -35,16 +35,15 @@ class GLES3GPUDescriptorSetLayout; class CC_GLES3_API GLES3DescriptorSetLayout final : public DescriptorSetLayout { public: - GLES3DescriptorSetLayout(Device *device); + GLES3DescriptorSetLayout(); ~GLES3DescriptorSetLayout(); -public: - virtual bool initialize(const DescriptorSetLayoutInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES3GPUDescriptorSetLayout *gpuDescriptorSetLayout() const { return _gpuDescriptorSetLayout; } -private: +protected: + void doInit(const DescriptorSetLayoutInfo &info) override; + void doDestroy() override; + GLES3GPUDescriptorSetLayout *_gpuDescriptorSetLayout = nullptr; }; diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp index 41e5869b0f..170dd0281a 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.cpp @@ -46,42 +46,46 @@ namespace cc { namespace gfx { +GLES3Device *GLES3Device::_instance = nullptr; + +GLES3Device *GLES3Device::getInstance() { + return GLES3Device::_instance; +} + GLES3Device::GLES3Device() { + _API = API::GLES3; + _deviceName = "GLES3"; + + GLES3Device::_instance = this; } GLES3Device::~GLES3Device() { + GLES3Device::_instance = nullptr; } -bool GLES3Device::initialize(const DeviceInfo &info) { - _API = API::GLES3; - _deviceName = "GLES3"; - _width = info.width; - _height = info.height; - _nativeWidth = info.nativeWidth; - _nativeHeight = info.nativeHeight; - _windowHandle = info.windowHandle; +bool GLES3Device::doInit(const DeviceInfo &info) { + ContextInfo ctxInfo; + ctxInfo.windowHandle = _windowHandle; - _bindingMappingInfo = info.bindingMappingInfo; - if (!_bindingMappingInfo.bufferOffsets.size()) { - _bindingMappingInfo.bufferOffsets.push_back(0); - } - if (!_bindingMappingInfo.samplerOffsets.size()) { - _bindingMappingInfo.samplerOffsets.push_back(0); + _renderContext = CC_NEW(GLES3Context); + if (!_renderContext->initialize(ctxInfo)) { + destroy(); + return false; } + QueueInfo queueInfo; + queueInfo.type = QueueType::GRAPHICS; + _queue = createQueue(queueInfo); + + CommandBufferInfo cmdBuffInfo; + cmdBuffInfo.type = CommandBufferType::PRIMARY; + cmdBuffInfo.queue = _queue; + _cmdBuff = createCommandBuffer(cmdBuffInfo); + _gpuStateCache = CC_NEW(GLES3GPUStateCache); _gpuStagingBufferPool = CC_NEW(GLES3GPUStagingBufferPool); _gpuFramebufferCacheMap = CC_NEW(GLES3GPUFramebufferCacheMap(_gpuStateCache)); - ContextInfo ctxInfo; - ctxInfo.windowHandle = _windowHandle; - ctxInfo.sharedCtx = info.sharedCtx; - - _renderContext = CC_NEW(GLES3Context(this)); - if (!_renderContext->initialize(ctxInfo)) { - destroy(); - return false; - } bindRenderContext(true); String extStr = (const char *)glGetString(GL_EXTENSIONS); @@ -95,7 +99,7 @@ bool GLES3Device::initialize(const DeviceInfo &info) { _features[(uint)Feature::INSTANCED_ARRAYS] = true; _features[(uint)Feature::MULTIPLE_RENDER_TARGETS] = true; _features[(uint)Feature::BLEND_MINMAX] = true; - _features[(int)Feature::ELEMENT_INDEX_UINT] = true; + _features[(uint)Feature::ELEMENT_INDEX_UINT] = true; uint minorVersion = ((GLES3Context *)_context)->minor_ver(); if (minorVersion) @@ -155,15 +159,6 @@ bool GLES3Device::initialize(const DeviceInfo &info) { CC_LOG_INFO("NATIVE_SIZE: %d x %d", _nativeWidth, _nativeHeight); CC_LOG_INFO("COMPRESSED_FORMATS: %s", compressedFmts.c_str()); - QueueInfo queueInfo; - queueInfo.type = QueueType::GRAPHICS; - _queue = createQueue(queueInfo); - - CommandBufferInfo cmdBuffInfo; - cmdBuffInfo.type = CommandBufferType::PRIMARY; - cmdBuffInfo.queue = _queue; - _cmdBuff = createCommandBuffer(cmdBuffInfo); - glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, (GLint *)&_caps.maxVertexAttributes); glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, (GLint *)&_caps.maxVertexUniformVectors); glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, (GLint *)&_caps.maxFragmentUniformVectors); @@ -176,7 +171,7 @@ bool GLES3Device::initialize(const DeviceInfo &info) { glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, (GLint *)&_caps.uboOffsetAlignment); glGetIntegerv(GL_DEPTH_BITS, (GLint *)&_caps.depthBits); glGetIntegerv(GL_STENCIL_BITS, (GLint *)&_caps.stencilBits); - + if (minorVersion) { glGetIntegerv(GL_MAX_IMAGE_UNITS, (GLint *)&_caps.maxImageUnits); glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, (GLint *)&_caps.maxShaderStorageBlockSize); @@ -196,16 +191,25 @@ bool GLES3Device::initialize(const DeviceInfo &info) { return true; } -void GLES3Device::destroy() { - CC_SAFE_DESTROY(_queue); - CC_SAFE_DESTROY(_cmdBuff); +void GLES3Device::doDestroy() { CC_SAFE_DELETE(_gpuFramebufferCacheMap); CC_SAFE_DELETE(_gpuStagingBufferPool); CC_SAFE_DELETE(_gpuStateCache); + + CC_SAFE_DESTROY(_cmdBuff); + CC_SAFE_DESTROY(_queue); CC_SAFE_DESTROY(_deviceContext); CC_SAFE_DESTROY(_renderContext); } +void GLES3Device::releaseSurface(const uintptr_t windowHandle) { + ((GLES3Context *)_context)->releaseSurface(windowHandle); +} + +void GLES3Device::acquireSurface(const uintptr_t windowHandle) { + ((GLES3Context *)_context)->acquireSurface(windowHandle); +} + void GLES3Device::resize(uint width, uint height) { _width = width; _height = height; @@ -245,7 +249,7 @@ void GLES3Device::bindDeviceContext(bool bound) { ctxInfo.windowHandle = _windowHandle; ctxInfo.sharedCtx = _renderContext; - _deviceContext = CC_NEW(GLES3Context(this)); + _deviceContext = CC_NEW(GLES3Context); _deviceContext->initialize(ctxInfo); } _deviceContext->MakeCurrent(bound); @@ -259,65 +263,65 @@ void GLES3Device::bindDeviceContext(bool bound) { uint GLES3Device::getMinorVersion() const { return ((GLES3Context *)_context)->minor_ver(); } -CommandBuffer *GLES3Device::doCreateCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { - if (hasAgent || info.type == CommandBufferType::PRIMARY) return CC_NEW(GLES3PrimaryCommandBuffer(this)); - return CC_NEW(GLES3CommandBuffer(this)); +CommandBuffer *GLES3Device::createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { + if (hasAgent || info.type == CommandBufferType::PRIMARY) return CC_NEW(GLES3PrimaryCommandBuffer); + return CC_NEW(GLES3CommandBuffer); } Queue *GLES3Device::createQueue() { - return CC_NEW(GLES3Queue(this)); + return CC_NEW(GLES3Queue); } Buffer *GLES3Device::createBuffer() { - return CC_NEW(GLES3Buffer(this)); + return CC_NEW(GLES3Buffer); } Texture *GLES3Device::createTexture() { - return CC_NEW(GLES3Texture(this)); + return CC_NEW(GLES3Texture); } Sampler *GLES3Device::createSampler() { - return CC_NEW(GLES3Sampler(this)); + return CC_NEW(GLES3Sampler); } Shader *GLES3Device::createShader() { - return CC_NEW(GLES3Shader(this)); + return CC_NEW(GLES3Shader); } InputAssembler *GLES3Device::createInputAssembler() { - return CC_NEW(GLES3InputAssembler(this)); + return CC_NEW(GLES3InputAssembler); } RenderPass *GLES3Device::createRenderPass() { - return CC_NEW(GLES3RenderPass(this)); + return CC_NEW(GLES3RenderPass); } Framebuffer *GLES3Device::createFramebuffer() { - return CC_NEW(GLES3Framebuffer(this)); + return CC_NEW(GLES3Framebuffer); } DescriptorSet *GLES3Device::createDescriptorSet() { - return CC_NEW(GLES3DescriptorSet(this)); + return CC_NEW(GLES3DescriptorSet); } DescriptorSetLayout *GLES3Device::createDescriptorSetLayout() { - return CC_NEW(GLES3DescriptorSetLayout(this)); + return CC_NEW(GLES3DescriptorSetLayout); } PipelineLayout *GLES3Device::createPipelineLayout() { - return CC_NEW(GLES3PipelineLayout(this)); + return CC_NEW(GLES3PipelineLayout); } PipelineState *GLES3Device::createPipelineState() { - return CC_NEW(GLES3PipelineState(this)); + return CC_NEW(GLES3PipelineState); } GlobalBarrier *GLES3Device::createGlobalBarrier() { - return CC_NEW(GLES3GlobalBarrier(this)); + return CC_NEW(GLES3GlobalBarrier); } TextureBarrier *GLES3Device::createTextureBarrier() { - return CC_NEW(TextureBarrier(this)); + return CC_NEW(TextureBarrier); } void GLES3Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { diff --git a/native/cocos/renderer/gfx-gles3/GLES3Device.h b/native/cocos/renderer/gfx-gles3/GLES3Device.h index 7ee25c88f1..5f2bb8e552 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Device.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Device.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_DEVICE_H_ -#define CC_GFXGLES3_DEVICE_H_ +#pragma once #include "gfx-base/GFXDevice.h" @@ -38,8 +37,9 @@ class GLES3GPUFramebufferCacheMap; class CC_GLES3_API GLES3Device final : public Device { public: - GLES3Device(); - ~GLES3Device(); + static GLES3Device *getInstance(); + + ~GLES3Device() override; using Device::copyBuffersToTexture; using Device::createBuffer; @@ -58,17 +58,16 @@ public: using Device::createTexture; using Device::createTextureBarrier; - virtual bool initialize(const DeviceInfo &info) override; - virtual void destroy() override; - virtual void resize(uint width, uint height) override; - virtual void acquire() override; - virtual void present() override; + void resize(uint width, uint height) override; + void acquire() override; + void present() override; - CC_INLINE GLES3GPUStateCache *stateCache() const { return _gpuStateCache; } - CC_INLINE GLES3GPUStagingBufferPool *stagingBufferPool() const { return _gpuStagingBufferPool; } - CC_INLINE GLES3GPUFramebufferCacheMap *framebufferCacheMap() const { return _gpuFramebufferCacheMap; } + inline GLES3GPUStateCache * stateCache() const { return _gpuStateCache; } + inline GLES3GPUStagingBufferPool * stagingBufferPool() const { return _gpuStagingBufferPool; } + inline GLES3GPUFramebufferCacheMap *framebufferCacheMap() const { return _gpuFramebufferCacheMap; } + inline uint getThreadID() const { return _threadID; } - CC_INLINE bool checkExtension(const String &extension) const { + inline bool checkExtension(const String &extension) const { for (size_t i = 0; i < _extensions.size(); ++i) { if (_extensions[i].find(extension) != String::npos) { return true; @@ -77,31 +76,41 @@ public: return false; } - CC_INLINE uint getThreadID() const { return _threadID; } - uint getMinorVersion() const; + uint getMinorVersion() const; protected: - virtual CommandBuffer * doCreateCommandBuffer(const CommandBufferInfo &info, bool hasAgent) override; - virtual Queue * createQueue() override; - virtual Buffer * createBuffer() override; - virtual Texture * createTexture() override; - virtual Sampler * createSampler() override; - virtual Shader * createShader() override; - virtual InputAssembler * createInputAssembler() override; - virtual RenderPass * createRenderPass() override; - virtual Framebuffer * createFramebuffer() override; - virtual DescriptorSet * createDescriptorSet() override; - virtual DescriptorSetLayout *createDescriptorSetLayout() override; - virtual PipelineLayout * createPipelineLayout() override; - virtual PipelineState * createPipelineState() override; - virtual GlobalBarrier * createGlobalBarrier() override; - virtual TextureBarrier * createTextureBarrier() override; - virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; + static GLES3Device *_instance; - virtual void bindRenderContext(bool bound) override; - virtual void bindDeviceContext(bool bound) override; + friend class DeviceCreator; + friend class GLES3Context; + + GLES3Device(); + + bool doInit(const DeviceInfo &info) override; + void doDestroy() override; + CommandBuffer * createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) override; + Queue * createQueue() override; + Buffer * createBuffer() override; + Texture * createTexture() override; + Sampler * createSampler() override; + Shader * createShader() override; + InputAssembler * createInputAssembler() override; + RenderPass * createRenderPass() override; + Framebuffer * createFramebuffer() override; + DescriptorSet * createDescriptorSet() override; + DescriptorSetLayout *createDescriptorSetLayout() override; + PipelineLayout * createPipelineLayout() override; + PipelineState * createPipelineState() override; + GlobalBarrier * createGlobalBarrier() override; + TextureBarrier * createTextureBarrier() override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; + + void releaseSurface(uintptr_t windowHandle) override; + void acquireSurface(uintptr_t windowHandle) override; + + void bindRenderContext(bool bound) override; + void bindDeviceContext(bool bound) override; -private: GLES3Context * _renderContext = nullptr; GLES3Context * _deviceContext = nullptr; GLES3GPUStateCache * _gpuStateCache = nullptr; @@ -115,5 +124,3 @@ private: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp index e97f4f0cbc..1a7fee1ee4 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.cpp @@ -24,29 +24,26 @@ ****************************************************************************/ #include "GLES3Std.h" + #include "GLES3Framebuffer.h" -#include "GLES3RenderPass.h" +#include "GLES3Device.h" #include "GLES3Commands.h" +#include "GLES3RenderPass.h" #include "GLES3Texture.h" namespace cc { namespace gfx { -GLES3Framebuffer::GLES3Framebuffer(Device *device) -: Framebuffer(device) { +GLES3Framebuffer::GLES3Framebuffer() +: Framebuffer() { } GLES3Framebuffer::~GLES3Framebuffer() { } -bool GLES3Framebuffer::initialize(const FramebufferInfo &info) { - - _renderPass = info.renderPass; - _colorTextures = info.colorTextures; - _depthStencilTexture = info.depthStencilTexture; - - _gpuFBO = CC_NEW(GLES3GPUFramebuffer); - _gpuFBO->gpuRenderPass = ((GLES3RenderPass *)_renderPass)->gpuRenderPass(); +void GLES3Framebuffer::doInit(const FramebufferInfo &info) { + _gpuFBO = CC_NEW(GLES3GPUFramebuffer); + _gpuFBO->gpuRenderPass = ((GLES3RenderPass *)_renderPass)->gpuRenderPass(); _gpuFBO->depthStencilMipmapLevel = info.depthStencilMipmapLevel; for (uint mipLevel : info.colorMipmapLevels) { _gpuFBO->colorMipmapLevels.push_back(mipLevel); @@ -64,14 +61,12 @@ bool GLES3Framebuffer::initialize(const FramebufferInfo &info) { _gpuFBO->gpuDepthStencilTexture = ((GLES3Texture *)_depthStencilTexture)->gpuTexture(); } - GLES3CmdFuncCreateFramebuffer((GLES3Device *)_device, _gpuFBO); - - return true; + GLES3CmdFuncCreateFramebuffer(GLES3Device::getInstance(), _gpuFBO); } -void GLES3Framebuffer::destroy() { +void GLES3Framebuffer::doDestroy() { if (_gpuFBO) { - GLES3CmdFuncDestroyFramebuffer((GLES3Device *)_device, _gpuFBO); + GLES3CmdFuncDestroyFramebuffer(GLES3Device::getInstance(), _gpuFBO); CC_DELETE(_gpuFBO); _gpuFBO = nullptr; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.h b/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.h index ede4a77926..b428502b5b 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Framebuffer.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_FRAMEBUFFER_H_ -#define CC_GFXGLES3_FRAMEBUFFER_H_ +#pragma once #include "gfx-base/GFXFramebuffer.h" @@ -35,20 +34,17 @@ class GLES3GPUFramebuffer; class CC_GLES3_API GLES3Framebuffer final : public Framebuffer { public: - GLES3Framebuffer(Device *device); + GLES3Framebuffer(); ~GLES3Framebuffer(); -public: - virtual bool initialize(const FramebufferInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES3GPUFramebuffer *gpuFBO() const { return _gpuFBO; } -private: +protected: + void doInit(const FramebufferInfo &info) override; + void doDestroy() override; + GLES3GPUFramebuffer *_gpuFBO = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h b/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h index 8572c076ce..e2a40e21dc 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h +++ b/native/cocos/renderer/gfx-gles3/GLES3GPUObjects.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_GPU_OBJECTS_H_ -#define CC_GFXGLES3_GPU_OBJECTS_H_ +#pragma once #include "gfx-base/GFXDef.h" #include "GLES3Wrangler.h" @@ -484,5 +483,3 @@ private: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3GlobalBarrier.cpp b/native/cocos/renderer/gfx-gles3/GLES3GlobalBarrier.cpp index 0ff0517c56..de6774d493 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3GlobalBarrier.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3GlobalBarrier.cpp @@ -31,17 +31,15 @@ namespace cc { namespace gfx { -GLES3GlobalBarrier::GLES3GlobalBarrier(Device *device) -: GlobalBarrier(device) { +GLES3GlobalBarrier::GLES3GlobalBarrier() +: GlobalBarrier() { } GLES3GlobalBarrier::~GLES3GlobalBarrier() { CC_SAFE_DELETE(_gpuBarrier); } -bool GLES3GlobalBarrier::initialize(const GlobalBarrierInfo &info) { - _info = info; - +void GLES3GlobalBarrier::doInit(const GlobalBarrierInfo &info) { _gpuBarrier = CC_NEW(GLES3GPUGlobalBarrier); bool hasShaderWrites = false; @@ -123,8 +121,6 @@ bool GLES3GlobalBarrier::initialize(const GlobalBarrierInfo &info) { } } } - - return true; } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3GlobalBarrier.h b/native/cocos/renderer/gfx-gles3/GLES3GlobalBarrier.h index 5312e5f7ac..cc4af621c5 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3GlobalBarrier.h +++ b/native/cocos/renderer/gfx-gles3/GLES3GlobalBarrier.h @@ -23,9 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_GLOBAL_BARRIER_H_ -#define CC_GFXGLES3_GLOBAL_BARRIER_H_ - +#pragma once #include "gfx-base/GFXGlobalBarrier.h" namespace cc { @@ -35,18 +33,16 @@ class GLES3GPUGlobalBarrier; class CC_DLL GLES3GlobalBarrier : public GlobalBarrier { public: - GLES3GlobalBarrier(Device *device); + GLES3GlobalBarrier(); ~GLES3GlobalBarrier(); CC_INLINE const GLES3GPUGlobalBarrier *gpuBarrier() const { return _gpuBarrier; } protected: - bool initialize(const GlobalBarrierInfo &info) override; + void doInit(const GlobalBarrierInfo &info) override; GLES3GPUGlobalBarrier *_gpuBarrier = nullptr; }; } // namespace gfx } // namespace cc - -#endif // CC_GFXVULKAN_GLOBAL_BARRIER_H_ diff --git a/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cpp b/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cpp index a16f0ddff9..72fea3adfb 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.cpp @@ -24,41 +24,28 @@ ****************************************************************************/ #include "GLES3Std.h" -#include "GLES3InputAssembler.h" -#include "GLES3Commands.h" + #include "GLES3Buffer.h" +#include "GLES3Commands.h" +#include "GLES3Device.h" +#include "GLES3InputAssembler.h" namespace cc { namespace gfx { -GLES3InputAssembler::GLES3InputAssembler(Device *device) -: InputAssembler(device) { +GLES3InputAssembler::GLES3InputAssembler() +: InputAssembler() { } GLES3InputAssembler::~GLES3InputAssembler() { } -bool GLES3InputAssembler::initialize(const InputAssemblerInfo &info) { - - _attributes = info.attributes; - _vertexBuffers = info.vertexBuffers; - _indexBuffer = info.indexBuffer; - _indirectBuffer = info.indirectBuffer; - - if (_indexBuffer) { - _indexCount = _indexBuffer->getCount(); - _firstIndex = 0; - } else if (_vertexBuffers.size()) { - _vertexCount = _vertexBuffers[0]->getCount(); - _firstVertex = 0; - _vertexOffset = 0; - } - - _gpuInputAssembler = CC_NEW(GLES3GPUInputAssembler); +void GLES3InputAssembler::doInit(const InputAssemblerInfo &info) { + _gpuInputAssembler = CC_NEW(GLES3GPUInputAssembler); _gpuInputAssembler->attributes = _attributes; _gpuInputAssembler->gpuVertexBuffers.resize(_vertexBuffers.size()); for (size_t i = 0; i < _gpuInputAssembler->gpuVertexBuffers.size(); ++i) { - GLES3Buffer *vb = (GLES3Buffer *)_vertexBuffers[i]; + GLES3Buffer *vb = (GLES3Buffer *)_vertexBuffers[i]; _gpuInputAssembler->gpuVertexBuffers[i] = vb->gpuBuffer(); } if (info.indexBuffer) @@ -67,26 +54,23 @@ bool GLES3InputAssembler::initialize(const InputAssemblerInfo &info) { if (info.indirectBuffer) _gpuInputAssembler->gpuIndirectBuffer = static_cast(info.indirectBuffer)->gpuBuffer(); - GLES3CmdFuncCreateInputAssembler((GLES3Device *)_device, _gpuInputAssembler); - _attributesHash = computeAttributesHash(); - - return true; + GLES3CmdFuncCreateInputAssembler(GLES3Device::getInstance(), _gpuInputAssembler); } -void GLES3InputAssembler::destroy() { +void GLES3InputAssembler::doDestroy() { if (_gpuInputAssembler) { - GLES3CmdFuncDestroyInputAssembler((GLES3Device *)_device, _gpuInputAssembler); + GLES3CmdFuncDestroyInputAssembler(GLES3Device::getInstance(), _gpuInputAssembler); CC_DELETE(_gpuInputAssembler); _gpuInputAssembler = nullptr; } } void GLES3InputAssembler::ExtractCmdDraw(GLES3CmdDraw *cmd) { - cmd->drawInfo.vertexCount = _vertexCount; - cmd->drawInfo.firstVertex = _firstVertex; - cmd->drawInfo.indexCount = _indexCount; - cmd->drawInfo.firstIndex = _firstIndex; - cmd->drawInfo.vertexOffset = _vertexOffset; + cmd->drawInfo.vertexCount = _vertexCount; + cmd->drawInfo.firstVertex = _firstVertex; + cmd->drawInfo.indexCount = _indexCount; + cmd->drawInfo.firstIndex = _firstIndex; + cmd->drawInfo.vertexOffset = _vertexOffset; cmd->drawInfo.instanceCount = _instanceCount; cmd->drawInfo.firstInstance = _firstInstance; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.h b/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.h index 8300438956..89314f69d6 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.h +++ b/native/cocos/renderer/gfx-gles3/GLES3InputAssembler.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_INPUT_ASSEMBLER_H_ -#define CC_GFXGLES3_INPUT_ASSEMBLER_H_ +#pragma once #include "gfx-base/GFXInputAssembler.h" @@ -36,22 +35,19 @@ class GLES3CmdDraw; class CC_GLES3_API GLES3InputAssembler final : public InputAssembler { public: - GLES3InputAssembler(Device *device); + GLES3InputAssembler(); ~GLES3InputAssembler(); -public: - virtual bool initialize(const InputAssemblerInfo &info) override; - virtual void destroy() override; - void ExtractCmdDraw(GLES3CmdDraw *cmd); CC_INLINE GLES3GPUInputAssembler *gpuInputAssembler() const { return _gpuInputAssembler; } -private: +protected: + void doInit(const InputAssemblerInfo &info) override; + void doDestroy() override; + GLES3GPUInputAssembler *_gpuInputAssembler = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cpp b/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cpp index 1cbc78bfa9..ee7f94423e 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.cpp @@ -32,17 +32,14 @@ namespace cc { namespace gfx { -GLES3PipelineLayout::GLES3PipelineLayout(Device *device) -: PipelineLayout(device) { +GLES3PipelineLayout::GLES3PipelineLayout() +: PipelineLayout() { } GLES3PipelineLayout::~GLES3PipelineLayout() { } -bool GLES3PipelineLayout::initialize(const PipelineLayoutInfo &info) { - - _setLayouts = info.setLayouts; - +void GLES3PipelineLayout::doInit(const PipelineLayoutInfo &info) { _gpuPipelineLayout = CC_NEW(GLES3GPUPipelineLayout); uint offset = 0u; @@ -66,11 +63,9 @@ bool GLES3PipelineLayout::initialize(const PipelineLayoutInfo &info) { _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); _gpuPipelineLayout->dynamicOffsetCount = offset; _gpuPipelineLayout->dynamicOffsets.resize(offset); - - return true; } -void GLES3PipelineLayout::destroy() { +void GLES3PipelineLayout::doDestroy() { if (_gpuPipelineLayout) { CC_DELETE(_gpuPipelineLayout); diff --git a/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.h b/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.h index d158f92336..989c519b1c 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.h +++ b/native/cocos/renderer/gfx-gles3/GLES3PipelineLayout.h @@ -35,16 +35,15 @@ class GLES3GPUPipelineLayout; class CC_GLES3_API GLES3PipelineLayout final : public PipelineLayout { public: - GLES3PipelineLayout(Device *device); + GLES3PipelineLayout(); ~GLES3PipelineLayout(); -public: - virtual bool initialize(const PipelineLayoutInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES3GPUPipelineLayout *gpuPipelineLayout() const { return _gpuPipelineLayout; } -private: +protected: + void doInit(const PipelineLayoutInfo &info) override; + void doDestroy() override; + GLES3GPUPipelineLayout *_gpuPipelineLayout = nullptr; }; diff --git a/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp b/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp index 5207968ad5..3b39083052 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3PipelineState.cpp @@ -51,25 +51,14 @@ const GLenum GLES3Primitives[] = { GL_NONE, }; -GLES3PipelineState::GLES3PipelineState(Device *device) -: PipelineState(device) { +GLES3PipelineState::GLES3PipelineState() +: PipelineState() { } GLES3PipelineState::~GLES3PipelineState() { } -bool GLES3PipelineState::initialize(const PipelineStateInfo &info) { - _primitive = info.primitive; - _shader = info.shader; - _inputState = info.inputState; - _rasterizerState = info.rasterizerState; - _depthStencilState = info.depthStencilState; - _bindPoint = info.bindPoint; - _blendState = info.blendState; - _dynamicStates = info.dynamicStates; - _renderPass = info.renderPass; - _pipelineLayout = info.pipelineLayout; - +void GLES3PipelineState::doInit(const PipelineStateInfo &info) { _gpuPipelineState = CC_NEW(GLES3GPUPipelineState); _gpuPipelineState->glPrimitive = GLES3Primitives[(int)_primitive]; _gpuPipelineState->gpuShader = ((GLES3Shader *)_shader)->gpuShader(); @@ -84,11 +73,9 @@ bool GLES3PipelineState::initialize(const PipelineStateInfo &info) { _gpuPipelineState->dynamicStates.push_back((DynamicStateFlagBit)(1 << i)); } } - - return true; } -void GLES3PipelineState::destroy() { +void GLES3PipelineState::doDestroy() { if (_gpuPipelineState) { CC_DELETE(_gpuPipelineState); _gpuPipelineState = nullptr; diff --git a/native/cocos/renderer/gfx-gles3/GLES3PipelineState.h b/native/cocos/renderer/gfx-gles3/GLES3PipelineState.h index dad66fc3bb..15b228c03c 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PipelineState.h +++ b/native/cocos/renderer/gfx-gles3/GLES3PipelineState.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_PIPELINE_STATE_H_ -#define CC_GFXGLES3_PIPELINE_STATE_H_ +#pragma once #include "gfx-base/GFXPipelineState.h" @@ -35,20 +34,17 @@ class GLES3GPUPipelineState; class CC_GLES3_API GLES3PipelineState final : public PipelineState { public: - GLES3PipelineState(Device *device); + GLES3PipelineState(); ~GLES3PipelineState(); -public: - virtual bool initialize(const PipelineStateInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES3GPUPipelineState *gpuPipelineState() const { return _gpuPipelineState; } -private: +protected: + void doInit(const PipelineStateInfo &info) override; + void doDestroy() override; + GLES3GPUPipelineState *_gpuPipelineState = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp index 9e3cdea670..6d9760020e 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.cpp @@ -39,8 +39,8 @@ namespace cc { namespace gfx { -GLES3PrimaryCommandBuffer::GLES3PrimaryCommandBuffer(Device *device) -: GLES3CommandBuffer(device) { +GLES3PrimaryCommandBuffer::GLES3PrimaryCommandBuffer() +: GLES3CommandBuffer() { } GLES3PrimaryCommandBuffer::~GLES3PrimaryCommandBuffer() { @@ -68,12 +68,12 @@ void GLES3PrimaryCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuf GLES3GPURenderPass * gpuRenderPass = ((GLES3RenderPass *)renderPass)->gpuRenderPass(); GLES3GPUFramebuffer *gpuFramebuffer = ((GLES3Framebuffer *)fbo)->gpuFBO(); - GLES3CmdFuncBeginRenderPass((GLES3Device *)_device, gpuRenderPass, gpuFramebuffer, + GLES3CmdFuncBeginRenderPass(GLES3Device::getInstance(), gpuRenderPass, gpuFramebuffer, renderArea, gpuRenderPass->colorAttachments.size(), colors, depth, stencil); } void GLES3PrimaryCommandBuffer::endRenderPass() { - GLES3CmdFuncEndRenderPass((GLES3Device *)_device); + GLES3CmdFuncEndRenderPass(GLES3Device::getInstance()); _isInRenderPass = false; } @@ -87,7 +87,7 @@ void GLES3PrimaryCommandBuffer::draw(InputAssembler *ia) { DrawInfo drawInfo; ia->extractDrawInfo(drawInfo); - GLES3CmdFuncDraw((GLES3Device *)_device, drawInfo); + GLES3CmdFuncDraw(GLES3Device::getInstance(), drawInfo); ++_numDrawCalls; _numInstances += ia->getInstanceCount(); @@ -117,7 +117,7 @@ void GLES3PrimaryCommandBuffer::updateBuffer(Buffer *buff, const void *data, uin GLES3GPUBuffer *gpuBuffer = ((GLES3Buffer *)buff)->gpuBuffer(); if (gpuBuffer) { - GLES3CmdFuncUpdateBuffer((GLES3Device *)_device, gpuBuffer, data, 0u, size); + GLES3CmdFuncUpdateBuffer(GLES3Device::getInstance(), gpuBuffer, data, 0u, size); } } else { CC_LOG_ERROR("Command 'updateBuffer' must be recorded outside a render pass."); @@ -130,7 +130,7 @@ void GLES3PrimaryCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffe GLES3GPUTexture *gpuTexture = ((GLES3Texture *)texture)->gpuTexture(); if (gpuTexture) { - GLES3CmdFuncCopyBuffersToTexture((GLES3Device *)_device, buffers, gpuTexture, regions, count); + GLES3CmdFuncCopyBuffersToTexture(GLES3Device::getInstance(), buffers, gpuTexture, regions, count); } } else { CC_LOG_ERROR("Command 'copyBuffersToTexture' must be recorded outside a render pass."); @@ -146,7 +146,7 @@ void GLES3PrimaryCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTex if (srcTexture) gpuTextureSrc = ((GLES3Texture *)srcTexture)->gpuTexture(); if (dstTexture) gpuTextureDst = ((GLES3Texture *)dstTexture)->gpuTexture(); - GLES3CmdFuncBlitTexture((GLES3Device *)_device, gpuTextureSrc, gpuTextureDst, regions, count, filter); + GLES3CmdFuncBlitTexture(GLES3Device::getInstance(), gpuTextureSrc, gpuTextureDst, regions, count, filter); } else { CC_LOG_ERROR("Command 'blitTexture' must be recorded outside a render pass."); } @@ -159,7 +159,7 @@ void GLES3PrimaryCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint32_t if (!cmdBuff->_pendingPackages.empty()) { GLES3CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); - GLES3CmdFuncExecuteCmds((GLES3Device *)_device, cmdPackage); + GLES3CmdFuncExecuteCmds(GLES3Device::getInstance(), cmdPackage); cmdBuff->_pendingPackages.pop(); cmdBuff->_freePackages.push(cmdPackage); @@ -182,7 +182,7 @@ void GLES3PrimaryCommandBuffer::BindStates() { count = std::min(count, _curDynamicOffsets[i].size()); if (count) memcpy(&dynamicOffsets[dynamicOffsetOffsets[i]], _curDynamicOffsets[i].data(), count * sizeof(uint)); } - GLES3CmdFuncBindState((GLES3Device *)_device, _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets, dynamicOffsets, + GLES3CmdFuncBindState(GLES3Device::getInstance(), _curGPUPipelineState, _curGPUInputAssember, _curGPUDescriptorSets, dynamicOffsets, _curViewport, _curScissor, _curLineWidth, false, _curDepthBias, _curBlendConstants, _curDepthBounds, _curStencilWriteMask, _curStencilCompareMask); _isStateInvalid = false; @@ -205,7 +205,7 @@ void GLES3PrimaryCommandBuffer::dispatch(const DispatchInfo &info) { gpuInfo.groupCountY = info.groupCountY; gpuInfo.groupCountZ = info.groupCountZ; } - GLES3CmdFuncDispatch((GLES3Device *)_device, gpuInfo); + GLES3CmdFuncDispatch(GLES3Device::getInstance(), gpuInfo); } else { CC_LOG_ERROR("Command 'dispatch' must be recorded outside a render pass."); } @@ -217,7 +217,7 @@ void GLES3PrimaryCommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, co if (!barrier) return; const GLES3GPUGlobalBarrier *gpuBarrier = ((GLES3GlobalBarrier *)barrier)->gpuBarrier(); - GLES3CmdFuncMemoryBarrier((GLES3Device *)_device, gpuBarrier->glBarriers, gpuBarrier->glBarriersByRegion); + GLES3CmdFuncMemoryBarrier(GLES3Device::getInstance(), gpuBarrier->glBarriers, gpuBarrier->glBarriersByRegion); } else { CC_LOG_ERROR("Command 'pipelineBarrier' must be recorded outside a render pass."); } diff --git a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h index 8a2b7b78d7..5fa90cc561 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h +++ b/native/cocos/renderer/gfx-gles3/GLES3PrimaryCommandBuffer.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_PRIMARY_COMMAND_BUFFER_H_ -#define CC_GFXGLES3_PRIMARY_COMMAND_BUFFER_H_ +#pragma once #include "GLES3CommandBuffer.h" @@ -32,29 +31,27 @@ namespace cc { namespace gfx { class CC_GLES3_API GLES3PrimaryCommandBuffer final : public GLES3CommandBuffer { - friend class GLES3Queue; - public: - GLES3PrimaryCommandBuffer(Device *device); + GLES3PrimaryCommandBuffer(); ~GLES3PrimaryCommandBuffer(); - virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; - virtual void end() override; - virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; - virtual void endRenderPass() override; - virtual void draw(InputAssembler *ia) override; - virtual void updateBuffer(Buffer *buff, const void *data, uint size) override; - virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; - virtual void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override; - virtual void dispatch(const DispatchInfo &info) override; - virtual void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) override; - virtual void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; + void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void end() override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void endRenderPass() override; + void draw(InputAssembler *ia) 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 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; protected: - virtual void BindStates() override; + friend class GLES3Queue; + + void BindStates() override; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp b/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp index 83b9f301d7..69a5b75a88 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Queue.cpp @@ -24,27 +24,26 @@ ****************************************************************************/ #include "GLES3Std.h" -#include "GLES3Queue.h" -#include "GLES3Commands.h" + #include "GLES3CommandBuffer.h" +#include "GLES3Commands.h" +#include "GLES3Device.h" +#include "GLES3Queue.h" namespace cc { namespace gfx { -GLES3Queue::GLES3Queue(Device *device) -: Queue(device) { +GLES3Queue::GLES3Queue() +: Queue() { } GLES3Queue::~GLES3Queue() { } -bool GLES3Queue::initialize(const QueueInfo &info) { - _type = info.type; - - return true; +void GLES3Queue::doInit(const QueueInfo &info) { } -void GLES3Queue::destroy() { +void GLES3Queue::doDestroy() { } void GLES3Queue::submit(CommandBuffer *const *cmdBuffs, uint count) { @@ -54,7 +53,7 @@ void GLES3Queue::submit(CommandBuffer *const *cmdBuffs, uint count) { if (!cmdBuff->_pendingPackages.empty()) { GLES3CmdPackage *cmdPackage = cmdBuff->_pendingPackages.front(); - GLES3CmdFuncExecuteCmds((GLES3Device *)_device, cmdPackage); + GLES3CmdFuncExecuteCmds(GLES3Device::getInstance(), cmdPackage); cmdBuff->_pendingPackages.pop(); cmdBuff->_freePackages.push(cmdPackage); diff --git a/native/cocos/renderer/gfx-gles3/GLES3Queue.h b/native/cocos/renderer/gfx-gles3/GLES3Queue.h index a6fbedb416..030187e976 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Queue.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Queue.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_QUEUE_H_ -#define CC_GFXGLES3_QUEUE_H_ +#pragma once #include "gfx-base/GFXQueue.h" @@ -33,17 +32,17 @@ namespace gfx { class CC_GLES3_API GLES3Queue final : public Queue { public: - GLES3Queue(Device *device); + GLES3Queue(); ~GLES3Queue(); + void submit(CommandBuffer *const *cmdBuffs, uint count) override; + +protected: friend class GLES3Device; -public: - virtual bool initialize(const QueueInfo &info) override; - virtual void destroy() override; - virtual void submit(CommandBuffer *const *cmdBuffs, uint count) override; + void doInit(const QueueInfo &info) override; + void doDestroy() override; -private: uint _numDrawCalls = 0; uint _numInstances = 0; uint _numTriangles = 0; @@ -51,5 +50,3 @@ private: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3RenderPass.cpp b/native/cocos/renderer/gfx-gles3/GLES3RenderPass.cpp index 98c6b2a30b..92a99c90ad 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3RenderPass.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3RenderPass.cpp @@ -30,28 +30,20 @@ namespace cc { namespace gfx { -GLES3RenderPass::GLES3RenderPass(Device *device) -: RenderPass(device) { +GLES3RenderPass::GLES3RenderPass() +: RenderPass() { } GLES3RenderPass::~GLES3RenderPass() { } -bool GLES3RenderPass::initialize(const RenderPassInfo &info) { - - _colorAttachments = info.colorAttachments; - _depthStencilAttachment = info.depthStencilAttachment; - +void GLES3RenderPass::doInit(const RenderPassInfo &info) { _gpuRenderPass = CC_NEW(GLES3GPURenderPass); _gpuRenderPass->colorAttachments = _colorAttachments; _gpuRenderPass->depthStencilAttachment = _depthStencilAttachment; - - _hash = computeHash(); - - return true; } -void GLES3RenderPass::destroy() { +void GLES3RenderPass::doDestroy() { if (_gpuRenderPass) { CC_DELETE(_gpuRenderPass); _gpuRenderPass = nullptr; diff --git a/native/cocos/renderer/gfx-gles3/GLES3RenderPass.h b/native/cocos/renderer/gfx-gles3/GLES3RenderPass.h index 79d502e61a..ff265304e8 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3RenderPass.h +++ b/native/cocos/renderer/gfx-gles3/GLES3RenderPass.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_RENDER_PASS_H_ -#define CC_GFXGLES3_RENDER_PASS_H_ +#pragma once #include "gfx-base/GFXRenderPass.h" @@ -35,20 +34,17 @@ class GLES3GPURenderPass; class CC_GLES3_API GLES3RenderPass final : public RenderPass { public: - GLES3RenderPass(Device *device); + GLES3RenderPass(); ~GLES3RenderPass(); -public: - virtual bool initialize(const RenderPassInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES3GPURenderPass *gpuRenderPass() const { return _gpuRenderPass; } -private: +protected: + void doInit(const RenderPassInfo &info) override; + void doDestroy() override; + GLES3GPURenderPass *_gpuRenderPass = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3Sampler.cpp b/native/cocos/renderer/gfx-gles3/GLES3Sampler.cpp index 76735a7cb9..048a083452 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Sampler.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Sampler.cpp @@ -24,47 +24,36 @@ ****************************************************************************/ #include "GLES3Std.h" -#include "GLES3Sampler.h" + #include "GLES3Commands.h" +#include "GLES3Device.h" +#include "GLES3Sampler.h" namespace cc { namespace gfx { -GLES3Sampler::GLES3Sampler(Device *device) -: Sampler(device) { +GLES3Sampler::GLES3Sampler() +: Sampler() { } GLES3Sampler::~GLES3Sampler() { } -bool GLES3Sampler::initialize(const SamplerInfo &info) { - _minFilter = info.minFilter; - _magFilter = info.magFilter; - _mipFilter = info.mipFilter; - _addressU = info.addressU; - _addressV = info.addressV; - _addressW = info.addressW; - _maxAnisotropy = info.maxAnisotropy; - _cmpFunc = info.cmpFunc; - _borderColor = info.borderColor; - _mipLODBias = info.mipLODBias; - - _gpuSampler = CC_NEW(GLES3GPUSampler); +void GLES3Sampler::doInit(const SamplerInfo &info) { + _gpuSampler = CC_NEW(GLES3GPUSampler); _gpuSampler->minFilter = _minFilter; _gpuSampler->magFilter = _magFilter; _gpuSampler->mipFilter = _mipFilter; - _gpuSampler->addressU = _addressU; - _gpuSampler->addressV = _addressV; - _gpuSampler->addressW = _addressW; + _gpuSampler->addressU = _addressU; + _gpuSampler->addressV = _addressV; + _gpuSampler->addressW = _addressW; - GLES3CmdFuncCreateSampler((GLES3Device *)_device, _gpuSampler); - - return true; + GLES3CmdFuncCreateSampler(GLES3Device::getInstance(), _gpuSampler); } -void GLES3Sampler::destroy() { +void GLES3Sampler::doDestroy() { if (_gpuSampler) { - GLES3CmdFuncDestroySampler((GLES3Device *)_device, _gpuSampler); + GLES3CmdFuncDestroySampler(GLES3Device::getInstance(), _gpuSampler); CC_DELETE(_gpuSampler); _gpuSampler = nullptr; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Sampler.h b/native/cocos/renderer/gfx-gles3/GLES3Sampler.h index 83efc34a80..58b284215f 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Sampler.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Sampler.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_SAMPLER_H_ -#define CC_GFXGLES3_SAMPLER_H_ +#pragma once #include "gfx-base/GFXSampler.h" @@ -35,20 +34,17 @@ class GLES3GPUSampler; class CC_GLES3_API GLES3Sampler final : public Sampler { public: - GLES3Sampler(Device *device); + GLES3Sampler(); ~GLES3Sampler(); -public: - virtual bool initialize(const SamplerInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES3GPUSampler *gpuSampler() const { return _gpuSampler; } -private: +protected: + void doInit(const SamplerInfo &info) override; + void doDestroy() override; + GLES3GPUSampler *_gpuSampler = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3Shader.cpp b/native/cocos/renderer/gfx-gles3/GLES3Shader.cpp index 24139d1c89..c8c6079ec0 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Shader.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Shader.cpp @@ -24,53 +24,42 @@ ****************************************************************************/ #include "GLES3Std.h" -#include "GLES3Shader.h" + #include "GLES3Commands.h" +#include "GLES3Device.h" +#include "GLES3Shader.h" namespace cc { namespace gfx { -GLES3Shader::GLES3Shader(Device *device) -: Shader(device) { +GLES3Shader::GLES3Shader() +: Shader() { } GLES3Shader::~GLES3Shader() { } -bool GLES3Shader::initialize(const ShaderInfo &info) { - _name = info.name; - _stages = info.stages; - _attributes = info.attributes; - _blocks = info.blocks; - _buffers = info.buffers; - _samplerTextures = info.samplerTextures; - _samplers = info.samplers; - _textures = info.textures; - _images = info.images; - _subpassInputs = info.subpassInputs; - - _gpuShader = CC_NEW(GLES3GPUShader); - _gpuShader->name = _name; - _gpuShader->blocks = _blocks; - _gpuShader->buffers = _buffers; +void GLES3Shader::doInit(const ShaderInfo &info) { + _gpuShader = CC_NEW(GLES3GPUShader); + _gpuShader->name = _name; + _gpuShader->blocks = _blocks; + _gpuShader->buffers = _buffers; _gpuShader->samplerTextures = _samplerTextures; - _gpuShader->samplers = _samplers; - _gpuShader->textures = _textures; - _gpuShader->images = _images; - _gpuShader->subpassInputs = _subpassInputs; + _gpuShader->samplers = _samplers; + _gpuShader->textures = _textures; + _gpuShader->images = _images; + _gpuShader->subpassInputs = _subpassInputs; for (const auto &stage : _stages) { GLES3GPUShaderStage gpuShaderStage = {stage.stage, stage.source}; _gpuShader->gpuStages.emplace_back(std::move(gpuShaderStage)); } - GLES3CmdFuncCreateShader((GLES3Device *)_device, _gpuShader); - - return true; + GLES3CmdFuncCreateShader(GLES3Device::getInstance(), _gpuShader); } -void GLES3Shader::destroy() { +void GLES3Shader::doDestroy() { if (_gpuShader) { - GLES3CmdFuncDestroyShader((GLES3Device *)_device, _gpuShader); + GLES3CmdFuncDestroyShader(GLES3Device::getInstance(), _gpuShader); CC_DELETE(_gpuShader); _gpuShader = nullptr; } diff --git a/native/cocos/renderer/gfx-gles3/GLES3Shader.h b/native/cocos/renderer/gfx-gles3/GLES3Shader.h index 1fcdce63fc..8676161eb4 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Shader.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Shader.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_SHADER_H_ -#define CC_GFXGLES3_SHADER_H_ +#pragma once #include "gfx-base/GFXShader.h" @@ -35,20 +34,17 @@ class GLES3GPUShader; class CC_GLES3_API GLES3Shader final : public Shader { public: - GLES3Shader(Device *device); + GLES3Shader(); ~GLES3Shader(); -public: - virtual bool initialize(const ShaderInfo &info) override; - virtual void destroy() override; - CC_INLINE GLES3GPUShader *gpuShader() const { return _gpuShader; } -private: +protected: + void doInit(const ShaderInfo &info) override; + void doDestroy() override; + GLES3GPUShader *_gpuShader = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp b/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp index ff444d2acf..21b169d213 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp +++ b/native/cocos/renderer/gfx-gles3/GLES3Texture.cpp @@ -32,76 +32,15 @@ namespace cc { namespace gfx { -GLES3Texture::GLES3Texture(Device *device) -: Texture(device) { +GLES3Texture::GLES3Texture() +: Texture() { } GLES3Texture::~GLES3Texture() { } -bool GLES3Texture::initialize(const TextureInfo &info) { - - _type = info.type; - _usage = info.usage; - _format = info.format; - _width = info.width; - _height = info.height; - _depth = info.depth; - _layerCount = info.layerCount; - _levelCount = info.levelCount; - _samples = info.samples; - _flags = info.flags; - _size = FormatSize(_format, _width, _height, _depth); - -#if CC_DEBUG > 0 - switch (_format) { // device feature validation - case Format::D16: - if (_device->hasFeature(Feature::FORMAT_D16)) break; - CC_LOG_ERROR("D16 texture format is not supported on this backend"); - return false; - case Format::D16S8: - if (_device->hasFeature(Feature::FORMAT_D16S8)) break; - CC_LOG_WARNING("D16S8 texture format is not supported on this backend"); - return false; - case Format::D24: - if (_device->hasFeature(Feature::FORMAT_D24)) break; - CC_LOG_WARNING("D24 texture format is not supported on this backend"); - return false; - case Format::D24S8: - if (_device->hasFeature(Feature::FORMAT_D24S8)) break; - CC_LOG_WARNING("D24S8 texture format is not supported on this backend"); - return false; - case Format::D32F: - if (_device->hasFeature(Feature::FORMAT_D32F)) break; - CC_LOG_WARNING("D32F texture format is not supported on this backend"); - return false; - case Format::D32F_S8: - if (_device->hasFeature(Feature::FORMAT_D32FS8)) break; - CC_LOG_WARNING("D32FS8 texture format is not supported on this backend"); - return false; - case Format::RGB8: - if (_device->hasFeature(Feature::FORMAT_RGB8)) break; - CC_LOG_WARNING("RGB8 texture format is not supported on this backend"); - return false; - default: - break; - } -#endif - - if (_flags & TextureFlags::BAKUP_BUFFER) { - _buffer = (uint8_t *)CC_MALLOC(_size); - if (!_buffer) { - CC_LOG_ERROR("GLES3Texture: CC_MALLOC backup buffer failed."); - return false; - } - _device->getMemoryStatus().textureSize += _size; - } - +void GLES3Texture::doInit(const TextureInfo &info) { _gpuTexture = CC_NEW(GLES3GPUTexture); - if (!_gpuTexture) { - CC_LOG_ERROR("GLES3Texture: CC_NEW GLES3GPUTexture failed."); - return false; - } _gpuTexture->type = _type; _gpuTexture->format = _format; _gpuTexture->usage = _usage; @@ -115,64 +54,26 @@ bool GLES3Texture::initialize(const TextureInfo &info) { _gpuTexture->flags = _flags; _gpuTexture->isPowerOf2 = math::IsPowerOfTwo(_width) && math::IsPowerOfTwo(_height); - GLES3CmdFuncCreateTexture((GLES3Device *)_device, _gpuTexture); - _device->getMemoryStatus().textureSize += _size; - - return true; + GLES3CmdFuncCreateTexture(GLES3Device::getInstance(), _gpuTexture); } -bool GLES3Texture::initialize(const TextureViewInfo &info) { - _isTextureView = true; - +void GLES3Texture::doInit(const TextureViewInfo &info) { CC_LOG_ERROR("GLES3 doesn't support texture view."); - return false; } -void GLES3Texture::destroy() { +void GLES3Texture::doDestroy() { if (_gpuTexture) { - GLES3CmdFuncDestroyTexture((GLES3Device *)_device, _gpuTexture); - _device->getMemoryStatus().textureSize -= _size; + GLES3CmdFuncDestroyTexture(GLES3Device::getInstance(), _gpuTexture); CC_DELETE(_gpuTexture); _gpuTexture = nullptr; } - - if (_buffer) { - CC_FREE(_buffer); - _device->getMemoryStatus().textureSize -= _size; - _buffer = nullptr; - } } -void GLES3Texture::resize(uint width, uint height) { - if (_width != width || _height != height) { - uint size = FormatSize(_format, width, height, _depth); - const uint oldSize = _size; - _width = width; - _height = height; - _size = size; - - MemoryStatus &status = _device->getMemoryStatus(); - _gpuTexture->width = _width; - _gpuTexture->height = _height; - _gpuTexture->size = _size; - GLES3CmdFuncResizeTexture((GLES3Device *)_device, _gpuTexture); - status.bufferSize -= oldSize; - status.bufferSize += _size; - - if (_buffer) { - const uint8_t *oldBuffer = _buffer; - uint8_t *buffer = (uint8_t *)CC_MALLOC(_size); - if (!buffer) { - CC_LOG_ERROR("GLES3Texture: CC_MALLOC backup buffer failed when resize the texture."); - return; - } - memcpy(buffer, oldBuffer, std::min(oldSize, size)); - _buffer = buffer; - CC_FREE(oldBuffer); - status.bufferSize -= oldSize; - status.bufferSize += _size; - } - } +void GLES3Texture::doResize(uint width, uint height) { + _gpuTexture->width = _width; + _gpuTexture->height = _height; + _gpuTexture->size = _size; + GLES3CmdFuncResizeTexture(GLES3Device::getInstance(), _gpuTexture); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-gles3/GLES3Texture.h b/native/cocos/renderer/gfx-gles3/GLES3Texture.h index 7c5ba1edc2..550844470c 100644 --- a/native/cocos/renderer/gfx-gles3/GLES3Texture.h +++ b/native/cocos/renderer/gfx-gles3/GLES3Texture.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXGLES3_TEXTURE_H_ -#define CC_GFXGLES3_TEXTURE_H_ +#pragma once #include "gfx-base/GFXTexture.h" @@ -35,22 +34,19 @@ class GLES3GPUTexture; class CC_GLES3_API GLES3Texture final : public Texture { public: - GLES3Texture(Device *device); + GLES3Texture(); ~GLES3Texture(); -public: - virtual bool initialize(const TextureInfo &info) override; - virtual bool initialize(const TextureViewInfo &info) override; - virtual void destroy() override; - virtual void resize(uint width, uint height) override; - CC_INLINE GLES3GPUTexture *gpuTexture() const { return _gpuTexture; } -private: +protected: + void doInit(const TextureInfo &info) override; + void doInit(const TextureViewInfo &info) override; + void doDestroy() override; + void doResize(uint width, uint height) override; + GLES3GPUTexture *_gpuTexture = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-metal/MTLBuffer.h b/native/cocos/renderer/gfx-metal/MTLBuffer.h index 997845d616..c7f9c3477c 100644 --- a/native/cocos/renderer/gfx-metal/MTLBuffer.h +++ b/native/cocos/renderer/gfx-metal/MTLBuffer.h @@ -39,17 +39,13 @@ class CCMTLRenderCommandEncoder; class CCMTLBuffer final : public Buffer { public: - explicit CCMTLBuffer(Device *device); + explicit CCMTLBuffer(); ~CCMTLBuffer() override = default; CCMTLBuffer(const CCMTLBuffer &) = delete; CCMTLBuffer(CCMTLBuffer &&) = delete; CCMTLBuffer &operator=(const CCMTLBuffer &) = default; CCMTLBuffer &operator=(CCMTLBuffer &&) = delete; - bool initialize(const BufferInfo &info) override; - bool initialize(const BufferViewInfo &info) override; - void destroy() override; - void resize(uint size) override; void update(void *buffer, uint offset) override; void encodeBuffer(CCMTLRenderCommandEncoder &encoder, uint offset, uint binding, ShaderStageFlags stages); @@ -59,7 +55,12 @@ public: CC_INLINE bool isDrawIndirectByIndex() const { return _isDrawIndirectByIndex; } CC_INLINE const DrawInfoList &getDrawInfos() const { return _drawInfos; } -private: +protected: + void doInit(const BufferInfo &info) override; + void doInit(const BufferViewInfo &info) override; + void doDestroy() override; + void doResize(uint size) override; + bool createMTLBuffer(uint size, MemoryUsage usage); void updateMTLBuffer(void *buffer, uint offset, uint size); diff --git a/native/cocos/renderer/gfx-metal/MTLBuffer.mm b/native/cocos/renderer/gfx-metal/MTLBuffer.mm index 4b172583bf..1240044a2f 100644 --- a/native/cocos/renderer/gfx-metal/MTLBuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLBuffer.mm @@ -37,17 +37,11 @@ namespace cc { namespace gfx { -CCMTLBuffer::CCMTLBuffer(Device *device) : Buffer(device) { +CCMTLBuffer::CCMTLBuffer() : Buffer() { } -bool CCMTLBuffer::initialize(const BufferInfo &info) { - _usage = info.usage; - _memUsage = info.memUsage; - _size = info.size; - _stride = std::max(info.stride, 1U); - _count = _size / _stride; - _flags = info.flags; - _isIndirectDrawSupported = static_cast(_device)->isIndirectDrawSupported(); +void CCMTLBuffer::doInit(const BufferInfo &info) { + _isIndirectDrawSupported = CCMTLDevice::getInstance()->isIndirectDrawSupported(); if (_usage & BufferUsage::INDEX) { switch (_stride) { case 4: _indexType = MTLIndexTypeUInt32; break; @@ -71,47 +65,39 @@ bool CCMTLBuffer::initialize(const BufferInfo &info) { _drawInfos.resize(_count); } } - - return true; } -bool CCMTLBuffer::initialize(const BufferViewInfo &info) { +void CCMTLBuffer::doInit(const BufferViewInfo &info) { *this = *static_cast(info.buffer); _bufferViewOffset = info.offset; _isBufferView = true; - return true; } bool CCMTLBuffer::createMTLBuffer(uint size, MemoryUsage usage) { _mtlResourceOptions = mu::toMTLResourceOption(usage); if (_mtlBuffer) { - Device *device = _device; + Device *device = CCMTLDevice::getInstance(); id mtlBuffer = _mtlBuffer; uint oldSize = [_mtlBuffer length]; std::function destroyFunc = [=]() { if (mtlBuffer) { [mtlBuffer release]; - device->getMemoryStatus().bufferSize -= oldSize; } }; //gpu object only CCMTLGPUGarbageCollectionPool::getInstance()->collect(destroyFunc); } - id mtlDevice = id(static_cast(_device)->getMTLDevice()); + id mtlDevice = id(CCMTLDevice::getInstance()->getMTLDevice()); _mtlBuffer = [mtlDevice newBufferWithLength:size options:_mtlResourceOptions]; if (_mtlBuffer == nil) { return false; } - - _device->getMemoryStatus().bufferSize += size; - - return true; } -void CCMTLBuffer::destroy() { +void CCMTLBuffer::doDestroy() { if (_isBufferView) { return; } @@ -128,7 +114,7 @@ void CCMTLBuffer::destroy() { _drawInfos.clear(); } - Device *device = _device; + Device *device = CCMTLDevice::getInstance(); id mtlBuffer = _mtlBuffer; _mtlBuffer = nil; uint size = _size; @@ -136,23 +122,13 @@ void CCMTLBuffer::destroy() { std::function destroyFunc = [=]() { if (mtlBuffer) { [mtlBuffer release]; - device->getMemoryStatus().bufferSize -= size; } }; //gpu object only CCMTLGPUGarbageCollectionPool::getInstance()->collect(destroyFunc); } -void CCMTLBuffer::resize(uint size) { - if (_isBufferView) { - CC_LOG_WARNING("Cannot resize a buffer view."); - return; - } - - if (_size == size) { - return; - } - +void CCMTLBuffer::doResize(uint size) { if (_usage & BufferUsageBit::VERTEX || _usage & BufferUsageBit::INDEX || _usage & BufferUsageBit::UNIFORM) { @@ -178,7 +154,7 @@ void CCMTLBuffer::update(void *buffer, uint size) { CC_LOG_WARNING("Cannot update a buffer view."); return; } - + uint drawInfoCount = size / _stride; const auto *drawInfo = static_cast(buffer); if (drawInfoCount > 0) { @@ -229,7 +205,7 @@ void CCMTLBuffer::update(void *buffer, uint size) { void CCMTLBuffer::updateMTLBuffer(void *buffer, uint /*offset*/, uint size) { if (_mtlBuffer) { - CommandBuffer *cmdBuffer = _device->getCommandBuffer(); + CommandBuffer *cmdBuffer = CCMTLDevice::getInstance()->getCommandBuffer(); cmdBuffer->begin(); static_cast(cmdBuffer)->updateBuffer(this, buffer, size); #if (CC_PLATFORM == CC_PLATFORM_MAC_OSX) diff --git a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.h b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.h index 50c7b4cf12..1ffff34cdd 100644 --- a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.h +++ b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.h @@ -42,18 +42,14 @@ class CCMTLRenderPass; class CCMTLFence; class CCMTLCommandBuffer final : public CommandBuffer { - friend class CCMTLQueue; - public: - explicit CCMTLCommandBuffer(Device *device); + explicit CCMTLCommandBuffer(); ~CCMTLCommandBuffer() override = default; CCMTLCommandBuffer(const CCMTLCommandBuffer &) = delete; CCMTLCommandBuffer(CCMTLCommandBuffer &&) = delete; CCMTLCommandBuffer &operator=(const CCMTLCommandBuffer &) = delete; CCMTLCommandBuffer &operator=(CCMTLCommandBuffer &&) = delete; - bool initialize(const CommandBufferInfo &info) override; - void destroy() override; void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; void end() override; void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; @@ -80,7 +76,12 @@ public: CC_INLINE bool isCommandBufferBegan() const { return _commandBufferBegan; } CC_INLINE id getMTLCommandBuffer() const { return _mtlCommandBuffer; } -private: +protected: + friend class CCMTLQueue; + + void doInit(const CommandBufferInfo &info) override; + void doDestroy() override; + void bindDescriptorSets(); static bool isRenderingEntireDrawable(const Rect &rect, const CCMTLRenderPass *renderPass); diff --git a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm index 3b372cf243..5beffe065c 100644 --- a/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLCommandBuffer.mm @@ -39,24 +39,22 @@ namespace cc { namespace gfx { -CCMTLCommandBuffer::CCMTLCommandBuffer(Device *device) -: CommandBuffer(device), - _mtlDevice(static_cast(device)), - _mtlCommandQueue(id((static_cast(device))->getMTLCommandQueue())), - _indirectDrawSuppotred(static_cast(device)->isIndirectDrawSupported()) { - const auto setCount = device->bindingMappingInfo().bufferOffsets.size(); +CCMTLCommandBuffer::CCMTLCommandBuffer() +: CommandBuffer(), + _mtlDevice(CCMTLDevice::getInstance()) { + _mtlCommandQueue = id(_mtlDevice->getMTLCommandQueue()); + _indirectDrawSuppotred = _mtlDevice->isIndirectDrawSupported(); + + const auto setCount = _mtlDevice->bindingMappingInfo().bufferOffsets.size(); _GPUDescriptorSets.resize(setCount); _dynamicOffsets.resize(setCount); _indirectDrawSuppotred = _mtlDevice->isIndirectDrawSupported(); } -bool CCMTLCommandBuffer::initialize(const CommandBufferInfo &info) { - _type = info.type; - _queue = info.queue; - return true; +void CCMTLCommandBuffer::doInit(const CommandBufferInfo &info) { } -void CCMTLCommandBuffer::destroy() { +void CCMTLCommandBuffer::doDestroy() { if (_autoreleasePool) { [_autoreleasePool release]; _autoreleasePool = nullptr; diff --git a/native/cocos/renderer/gfx-metal/MTLContext.h b/native/cocos/renderer/gfx-metal/MTLContext.h index 636e2864a2..dac5e3120c 100644 --- a/native/cocos/renderer/gfx-metal/MTLContext.h +++ b/native/cocos/renderer/gfx-metal/MTLContext.h @@ -32,16 +32,18 @@ namespace gfx { class CCMTLContext final : public Context { public: - explicit CCMTLContext(Device *device); + explicit CCMTLContext(); ~CCMTLContext() override = default; CCMTLContext(const CCMTLContext &)=delete; CCMTLContext(CCMTLContext &&)=delete; CCMTLContext &operator=(const CCMTLContext &)=delete; CCMTLContext &operator=(CCMTLContext &&)=delete; - bool initialize(const ContextInfo &info) override; - void destroy() override {} void present() override {} + +protected: + bool doInit(const ContextInfo &info) override; + void doDestroy() override {} }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-metal/MTLContext.mm b/native/cocos/renderer/gfx-metal/MTLContext.mm index a1f12ac77d..a86dfa81a7 100644 --- a/native/cocos/renderer/gfx-metal/MTLContext.mm +++ b/native/cocos/renderer/gfx-metal/MTLContext.mm @@ -49,15 +49,15 @@ Format toFormat(MTLPixelFormat format) { } } -CCMTLContext::CCMTLContext(Device *device) -: Context(device) { +CCMTLContext::CCMTLContext() +: Context() { } -bool CCMTLContext::initialize(const ContextInfo &info) { +bool CCMTLContext::doInit(const ContextInfo &info) { _vsyncMode = info.vsyncMode; _windowHandle = info.windowHandle; - CCMTLDevice *device = static_cast(_device); + CCMTLDevice *device = CCMTLDevice::getInstance(); CAMetalLayer *layer = (CAMetalLayer *)device->getMTLLayer(); _colorFmt = toFormat(layer.pixelFormat); id dssTex = (id)device->getDSSTexture(); diff --git a/native/cocos/renderer/gfx-metal/MTLDescriptorSet.h b/native/cocos/renderer/gfx-metal/MTLDescriptorSet.h index 123ecae489..c6065d9c95 100644 --- a/native/cocos/renderer/gfx-metal/MTLDescriptorSet.h +++ b/native/cocos/renderer/gfx-metal/MTLDescriptorSet.h @@ -34,20 +34,21 @@ class CCMTLGPUDescriptorSet; class CCMTLDescriptorSet final : public DescriptorSet { public: - explicit CCMTLDescriptorSet(Device *device); + explicit CCMTLDescriptorSet(); ~CCMTLDescriptorSet() override = default; CCMTLDescriptorSet(const CCMTLDescriptorSet &)=delete; CCMTLDescriptorSet(CCMTLDescriptorSet &&)=delete; CCMTLDescriptorSet &operator=(const CCMTLDescriptorSet &)=delete; CCMTLDescriptorSet &operator=(CCMTLDescriptorSet &&)=delete; - bool initialize(const DescriptorSetInfo &info) override; - void destroy() override; void update() override; CC_INLINE CCMTLGPUDescriptorSet *gpuDescriptorSet() const { return _gpuDescriptorSet; } -private: +protected: + void doInit(const DescriptorSetInfo &info) override; + void doDestroy() override; + CCMTLGPUDescriptorSet *_gpuDescriptorSet = nullptr; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-metal/MTLDescriptorSet.mm b/native/cocos/renderer/gfx-metal/MTLDescriptorSet.mm index 11dbef4a71..130688fdaf 100644 --- a/native/cocos/renderer/gfx-metal/MTLDescriptorSet.mm +++ b/native/cocos/renderer/gfx-metal/MTLDescriptorSet.mm @@ -34,20 +34,14 @@ namespace cc { namespace gfx { -CCMTLDescriptorSet::CCMTLDescriptorSet(Device *device) : DescriptorSet(device) { +CCMTLDescriptorSet::CCMTLDescriptorSet() : DescriptorSet() { } -bool CCMTLDescriptorSet::initialize(const DescriptorSetInfo &info) { - _layout = info.layout; - +void CCMTLDescriptorSet::doInit(const DescriptorSetInfo &info) { const auto gpuDescriptorSetLayout = static_cast(_layout)->gpuDescriptorSetLayout(); const auto descriptorCount = gpuDescriptorSetLayout->descriptorCount; const auto bindingCount = gpuDescriptorSetLayout->bindings.size(); - _buffers.resize(descriptorCount); - _textures.resize(descriptorCount); - _samplers.resize(descriptorCount); - _gpuDescriptorSet = CC_NEW(CCMTLGPUDescriptorSet); _gpuDescriptorSet->descriptorIndices = &gpuDescriptorSetLayout->descriptorIndices; _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount); @@ -57,16 +51,10 @@ bool CCMTLDescriptorSet::initialize(const DescriptorSetInfo &info) { _gpuDescriptorSet->gpuDescriptors[k].type = binding.descriptorType; } } - - return true; } -void CCMTLDescriptorSet::destroy() { - _layout = nullptr; + +void CCMTLDescriptorSet::doDestroy() { CC_SAFE_DELETE(_gpuDescriptorSet); - // do remember to clear these or else it might not be properly updated when reused - _buffers.clear(); - _textures.clear(); - _samplers.clear(); } void CCMTLDescriptorSet::update() { diff --git a/native/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.h b/native/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.h index 175e4d707d..3de5695e00 100644 --- a/native/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.h +++ b/native/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.h @@ -33,19 +33,19 @@ namespace gfx { class CCMTLGPUDescriptorSetLayout; class CCMTLDescriptorSetLayout final : public DescriptorSetLayout { public: - explicit CCMTLDescriptorSetLayout(Device *device); + explicit CCMTLDescriptorSetLayout(); ~CCMTLDescriptorSetLayout() override = default; CCMTLDescriptorSetLayout(const CCMTLDescriptorSetLayout &)=delete; CCMTLDescriptorSetLayout(CCMTLDescriptorSetLayout &&)=delete; CCMTLDescriptorSetLayout &operator=(const CCMTLDescriptorSetLayout &)=delete; CCMTLDescriptorSetLayout &operator=(CCMTLDescriptorSetLayout &&)=delete; - bool initialize(const DescriptorSetLayoutInfo &info) override; - void destroy() override; - CC_INLINE CCMTLGPUDescriptorSetLayout *gpuDescriptorSetLayout() const { return _gpuDescriptorSetLayout; } -private: +protected: + void doInit(const DescriptorSetLayoutInfo &info) override; + void doDestroy() override; + CCMTLGPUDescriptorSetLayout *_gpuDescriptorSetLayout = nullptr; }; diff --git a/native/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm b/native/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm index 123e4ed181..7f82b9258c 100644 --- a/native/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm +++ b/native/cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm @@ -31,40 +31,17 @@ namespace cc { namespace gfx { -CCMTLDescriptorSetLayout::CCMTLDescriptorSetLayout(Device *device) : DescriptorSetLayout(device) { +CCMTLDescriptorSetLayout::CCMTLDescriptorSetLayout() : DescriptorSetLayout() { } -bool CCMTLDescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { - _bindings = info.bindings; - const auto bindingCount = _bindings.size(); - _descriptorCount = 0; - - if (bindingCount) { - uint maxBinding = 0; - vector flattenedIndices(bindingCount); - for (auto i = 0; i < bindingCount; i++) { - const DescriptorSetLayoutBinding &binding = _bindings[i]; - flattenedIndices[i] = _descriptorCount; - _descriptorCount += binding.count; - if (binding.binding > maxBinding) maxBinding = binding.binding; - } - - _bindingIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); - _descriptorIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); - for (uint i = 0u; i < bindingCount; i++) { - const DescriptorSetLayoutBinding &binding = _bindings[i]; - _bindingIndices[binding.binding] = i; - _descriptorIndices[binding.binding] = flattenedIndices[i]; - } - } - +void CCMTLDescriptorSetLayout::doInit(const DescriptorSetLayoutInfo &info) { _gpuDescriptorSetLayout = CC_NEW(CCMTLGPUDescriptorSetLayout); _gpuDescriptorSetLayout->descriptorCount = _descriptorCount; _gpuDescriptorSetLayout->descriptorIndices = _descriptorIndices; _gpuDescriptorSetLayout->bindingIndices = _bindingIndices; _gpuDescriptorSetLayout->bindings = _bindings; - for (size_t i = 0; i < bindingCount; i++) { + for (size_t i = 0; i < _bindings.size(); i++) { const auto binding = _bindings[i]; if (binding.descriptorType & DESCRIPTOR_DYNAMIC_TYPE) { for (uint j = 0; j < binding.count; j++) { @@ -72,12 +49,11 @@ bool CCMTLDescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { } } } - return true; } -void CCMTLDescriptorSetLayout::destroy() { +void CCMTLDescriptorSetLayout::doDestroy() { CC_SAFE_DELETE(_gpuDescriptorSetLayout); } -} -} +} // namespace gfx +} // namespace cc diff --git a/native/cocos/renderer/gfx-metal/MTLDevice.h b/native/cocos/renderer/gfx-metal/MTLDevice.h index f33b922ed4..e8d62a58e7 100644 --- a/native/cocos/renderer/gfx-metal/MTLDevice.h +++ b/native/cocos/renderer/gfx-metal/MTLDevice.h @@ -36,8 +36,11 @@ class CCMTLSemaphore; class CCMTLDevice final : public Device { public: + static CCMTLDevice *getInstance(); + CCMTLDevice(); - ~CCMTLDevice() override = default; + ~CCMTLDevice() override; + CCMTLDevice(const CCMTLDevice &) = delete; CCMTLDevice(CCMTLDevice &&) = delete; CCMTLDevice &operator=(const CCMTLDevice &) = delete; @@ -60,8 +63,6 @@ public: using Device::createGlobalBarrier; using Device::createTextureBarrier; - bool initialize(const DeviceInfo &info) override; - void destroy() override; void resize(uint width, uint height) override; void acquire() override; void present() override; @@ -84,7 +85,13 @@ public: CC_INLINE void *getDSSTexture() const { return _dssTex; } protected: - CommandBuffer *doCreateCommandBuffer(const CommandBufferInfo &info, bool hasAgent) override; + static CCMTLDevice * _instance; + + friend class DeviceCreator; + + bool doInit(const DeviceInfo &info) override; + void doDestroy() override; + CommandBuffer *createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) override; Queue *createQueue() override; Buffer *createBuffer() override; Texture *createTexture() override; @@ -97,11 +104,10 @@ protected: DescriptorSetLayout *createDescriptorSetLayout() override; PipelineLayout *createPipelineLayout() override; PipelineState *createPipelineState() override; - virtual GlobalBarrier *createGlobalBarrier() override; - virtual TextureBarrier *createTextureBarrier() override; + GlobalBarrier *createGlobalBarrier() override; + TextureBarrier *createTextureBarrier() override; void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; -private: void onMemoryWarning(); void *_autoreleasePool = nullptr; diff --git a/native/cocos/renderer/gfx-metal/MTLDevice.mm b/native/cocos/renderer/gfx-metal/MTLDevice.mm index 0e380c21c9..a24f060449 100644 --- a/native/cocos/renderer/gfx-metal/MTLDevice.mm +++ b/native/cocos/renderer/gfx-metal/MTLDevice.mm @@ -48,29 +48,28 @@ namespace cc { namespace gfx { +CCMTLDevice *CCMTLDevice::_instance = nullptr; + +CCMTLDevice *CCMTLDevice::getInstance() { + return CCMTLDevice::_instance; +} + CCMTLDevice::CCMTLDevice() { + _API = API::METAL; + _deviceName = "Metal"; + _caps.clipSpaceMinZ = 0.0f; _caps.screenSpaceSignY = 1.0f; _caps.UVSpaceSignY = 1.0f; + + CCMTLDevice::_instance = this; } -bool CCMTLDevice::initialize(const DeviceInfo &info) { - _API = API::METAL; - _deviceName = "Metal"; - _width = info.width; - _height = info.height; - _nativeWidth = info.nativeWidth; - _nativeHeight = info.nativeHeight; - _windowHandle = info.windowHandle; - - _bindingMappingInfo = info.bindingMappingInfo; - if (!_bindingMappingInfo.bufferOffsets.size()) { - _bindingMappingInfo.bufferOffsets.push_back(0); - } - if (!_bindingMappingInfo.samplerOffsets.size()) { - _bindingMappingInfo.samplerOffsets.push_back(0); - } +CCMTLDevice::~CCMTLDevice() { + CCMTLDevice::_instance = nullptr; +} +bool CCMTLDevice::doInit(const DeviceInfo &info) { _inFlightSemaphore = CC_NEW(CCMTLSemaphore(MAX_FRAMES_IN_FLIGHT)); _currentFrameIndex = 0; @@ -112,23 +111,23 @@ bool CCMTLDevice::initialize(const DeviceInfo &info) { _dssTex = [mtlDevice newTextureWithDescriptor:dssDescriptor]; _caps.stencilBits = 8; - ContextInfo contextCreateInfo; - contextCreateInfo.windowHandle = _windowHandle; - contextCreateInfo.sharedCtx = info.sharedCtx; - _context = CC_NEW(CCMTLContext(this)); - if (!_context->initialize(contextCreateInfo)) { + ContextInfo ctxInfo; + ctxInfo.windowHandle = _windowHandle; + + _context = CC_NEW(CCMTLContext); + if (!_context->initialize(ctxInfo)) { destroy(); return false; } - QueueInfo queue_info; - queue_info.type = QueueType::GRAPHICS; - _queue = createQueue(queue_info); + QueueInfo queueInfo; + queueInfo.type = QueueType::GRAPHICS; + _queue = createQueue(queueInfo); CommandBufferInfo cmdBuffInfo; - cmdBuffInfo.type = CommandBufferType::PRIMARY; + cmdBuffInfo.type = CommandBufferType::PRIMARY; cmdBuffInfo.queue = _queue; - _cmdBuff = createCommandBuffer(cmdBuffInfo); + _cmdBuff = createCommandBuffer(cmdBuffInfo); for (int i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) { _gpuStagingBufferPools[i] = CC_NEW(CCMTLGPUStagingBufferPool(mtlDevice)); @@ -187,7 +186,7 @@ bool CCMTLDevice::initialize(const DeviceInfo &info) { return true; } -void CCMTLDevice::destroy() { +void CCMTLDevice::doDestroy() { // if (_memoryAlarmListenerId != 0) { // EventDispatcher::removeCustomEventListener(EVENT_MEMORY_WARNING, _memoryAlarmListenerId); // _memoryAlarmListenerId = 0; @@ -279,63 +278,63 @@ void CCMTLDevice::disposeCurrentDrawable() { } Queue *CCMTLDevice::createQueue() { - return CC_NEW(CCMTLQueue(this)); + return CC_NEW(CCMTLQueue); } -CommandBuffer *CCMTLDevice::doCreateCommandBuffer(const CommandBufferInfo &info, bool /*hasAgent*/) { - return CC_NEW(CCMTLCommandBuffer(this)); +CommandBuffer *CCMTLDevice::createCommandBuffer(const CommandBufferInfo &info, bool /*hasAgent*/) { + return CC_NEW(CCMTLCommandBuffer); } Buffer *CCMTLDevice::createBuffer() { - return CC_NEW(CCMTLBuffer(this)); + return CC_NEW(CCMTLBuffer); } Texture *CCMTLDevice::createTexture() { - return CC_NEW(CCMTLTexture(this)); + return CC_NEW(CCMTLTexture); } Sampler *CCMTLDevice::createSampler() { - return CC_NEW(CCMTLSampler(this)); + return CC_NEW(CCMTLSampler); } Shader *CCMTLDevice::createShader() { - return CC_NEW(CCMTLShader(this)); + return CC_NEW(CCMTLShader); } InputAssembler *CCMTLDevice::createInputAssembler() { - return CC_NEW(CCMTLInputAssembler(this)); + return CC_NEW(CCMTLInputAssembler); } RenderPass *CCMTLDevice::createRenderPass() { - return CC_NEW(CCMTLRenderPass(this)); + return CC_NEW(CCMTLRenderPass); } Framebuffer *CCMTLDevice::createFramebuffer() { - return CC_NEW(CCMTLFramebuffer(this)); + return CC_NEW(CCMTLFramebuffer); } DescriptorSet *CCMTLDevice::createDescriptorSet() { - return CC_NEW(CCMTLDescriptorSet(this)); + return CC_NEW(CCMTLDescriptorSet); } DescriptorSetLayout *CCMTLDevice::createDescriptorSetLayout() { - return CC_NEW(CCMTLDescriptorSetLayout(this)); + return CC_NEW(CCMTLDescriptorSetLayout); } PipelineLayout *CCMTLDevice::createPipelineLayout() { - return CC_NEW(CCMTLPipelineLayout(this)); + return CC_NEW(CCMTLPipelineLayout); } PipelineState *CCMTLDevice::createPipelineState() { - return CC_NEW(CCMTLPipelineState(this)); + return CC_NEW(CCMTLPipelineState); } GlobalBarrier *CCMTLDevice::createGlobalBarrier() { - return CC_NEW(GlobalBarrier(this)); + return CC_NEW(GlobalBarrier); } TextureBarrier *CCMTLDevice::createTextureBarrier() { - return CC_NEW(TextureBarrier(this)); + return CC_NEW(TextureBarrier); } void CCMTLDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { diff --git a/native/cocos/renderer/gfx-metal/MTLFramebuffer.h b/native/cocos/renderer/gfx-metal/MTLFramebuffer.h index f0ebc99796..764ef627fb 100644 --- a/native/cocos/renderer/gfx-metal/MTLFramebuffer.h +++ b/native/cocos/renderer/gfx-metal/MTLFramebuffer.h @@ -32,19 +32,19 @@ namespace gfx { class CCMTLFramebuffer final : public Framebuffer { public: - explicit CCMTLFramebuffer(Device *device); + explicit CCMTLFramebuffer(); ~CCMTLFramebuffer() override = default; CCMTLFramebuffer(const CCMTLFramebuffer &)=delete; CCMTLFramebuffer(CCMTLFramebuffer &&)=delete; CCMTLFramebuffer &operator=(const CCMTLFramebuffer &)=delete; CCMTLFramebuffer &operator=(CCMTLFramebuffer &&)=delete; - bool initialize(const FramebufferInfo &info) override; - void destroy() override; - CC_INLINE bool isOffscreen() const { return _isOffscreen; } -private: +protected: + void doInit(const FramebufferInfo &info) override; + void doDestroy() override; + bool _isOffscreen = false; }; diff --git a/native/cocos/renderer/gfx-metal/MTLFramebuffer.mm b/native/cocos/renderer/gfx-metal/MTLFramebuffer.mm index ce4f5f40f7..1f6bae0631 100644 --- a/native/cocos/renderer/gfx-metal/MTLFramebuffer.mm +++ b/native/cocos/renderer/gfx-metal/MTLFramebuffer.mm @@ -32,13 +32,9 @@ namespace cc { namespace gfx { -CCMTLFramebuffer::CCMTLFramebuffer(Device *device) : Framebuffer(device) {} - -bool CCMTLFramebuffer::initialize(const FramebufferInfo &info) { - _renderPass = info.renderPass; - _colorTextures = info.colorTextures; - _depthStencilTexture = info.depthStencilTexture; +CCMTLFramebuffer::CCMTLFramebuffer() : Framebuffer() {} +void CCMTLFramebuffer::doInit(const FramebufferInfo &info) { auto *mtlRenderPass = static_cast(_renderPass); size_t slot = 0; size_t levelCount = info.colorMipmapLevels.size(); @@ -64,11 +60,9 @@ bool CCMTLFramebuffer::initialize(const FramebufferInfo &info) { } _isOffscreen = (attachmentIndices != 0); - - return true; } -void CCMTLFramebuffer::destroy() { +void CCMTLFramebuffer::doDestroy() { } } // namespace gfx diff --git a/native/cocos/renderer/gfx-metal/MTLGPUObjects.h b/native/cocos/renderer/gfx-metal/MTLGPUObjects.h index d467491955..e1b8e655a0 100644 --- a/native/cocos/renderer/gfx-metal/MTLGPUObjects.h +++ b/native/cocos/renderer/gfx-metal/MTLGPUObjects.h @@ -218,7 +218,7 @@ public: } } -private: +protected: struct Buffer { id mtlBuffer = nil; vector> dynamicDataBuffers{MAX_FRAMES_IN_FLIGHT}; @@ -282,7 +282,7 @@ public: } } -private: +protected: //avoid cross-reference with CCMTLDevice std::function _getFrameIndex; std::queue _releaseQueue[MAX_FRAMES_IN_FLIGHT]; diff --git a/native/cocos/renderer/gfx-metal/MTLInputAssembler.h b/native/cocos/renderer/gfx-metal/MTLInputAssembler.h index e67b3b50b0..6aca7d4f42 100644 --- a/native/cocos/renderer/gfx-metal/MTLInputAssembler.h +++ b/native/cocos/renderer/gfx-metal/MTLInputAssembler.h @@ -33,20 +33,20 @@ namespace gfx { class CCMTLGPUInputAssembler; class CCMTLInputAssembler final : public InputAssembler { - friend class CCMTLQueue; - public: - explicit CCMTLInputAssembler(Device *device); + explicit CCMTLInputAssembler(); ~CCMTLInputAssembler() override = default; CCMTLInputAssembler(const CCMTLInputAssembler &)=delete; CCMTLInputAssembler(CCMTLInputAssembler &&)=delete; CCMTLInputAssembler &operator=(const CCMTLInputAssembler &)=delete; CCMTLInputAssembler &operator=(CCMTLInputAssembler &&)=delete; - bool initialize(const InputAssemblerInfo &info) override; - void destroy() override; +protected: + friend class CCMTLQueue; + + void doInit(const InputAssemblerInfo &info) override; + void doDestroy() override; -private: CCMTLGPUInputAssembler *_GPUInputAssembler = nullptr; }; diff --git a/native/cocos/renderer/gfx-metal/MTLInputAssembler.mm b/native/cocos/renderer/gfx-metal/MTLInputAssembler.mm index 2f496b3534..ba14cd1fa3 100644 --- a/native/cocos/renderer/gfx-metal/MTLInputAssembler.mm +++ b/native/cocos/renderer/gfx-metal/MTLInputAssembler.mm @@ -32,23 +32,9 @@ namespace cc { namespace gfx { -CCMTLInputAssembler::CCMTLInputAssembler(Device *device) : InputAssembler(device) {} - -bool CCMTLInputAssembler::initialize(const InputAssemblerInfo &info) { - _attributes = info.attributes; - _vertexBuffers = info.vertexBuffers; - _indexBuffer = info.indexBuffer; - _indirectBuffer = info.indirectBuffer; - - if (_indexBuffer) { - _indexCount = _indexBuffer->getCount(); - _firstIndex = 0; - } else if (_vertexBuffers.size()) { - _vertexCount = _vertexBuffers[0]->getCount(); - _firstVertex = 0; - _vertexOffset = 0; - } +CCMTLInputAssembler::CCMTLInputAssembler() : InputAssembler() {} +void CCMTLInputAssembler::doInit(const InputAssemblerInfo &info) { _GPUInputAssembler = CC_NEW(CCMTLGPUInputAssembler); if (!_GPUInputAssembler) { return false; @@ -63,13 +49,9 @@ bool CCMTLInputAssembler::initialize(const InputAssemblerInfo &info) { for (const auto &vertexBuffer : info.vertexBuffers) _GPUInputAssembler->mtlVertexBufers.push_back(static_cast(vertexBuffer)->getMTLBuffer()); - - _attributesHash = computeAttributesHash(); - - return true; } -void CCMTLInputAssembler::destroy() { +void CCMTLInputAssembler::doDestroy() { CC_SAFE_DELETE(_GPUInputAssembler); } diff --git a/native/cocos/renderer/gfx-metal/MTLPipelineLayout.h b/native/cocos/renderer/gfx-metal/MTLPipelineLayout.h index 105b5fbe15..7992b511b1 100644 --- a/native/cocos/renderer/gfx-metal/MTLPipelineLayout.h +++ b/native/cocos/renderer/gfx-metal/MTLPipelineLayout.h @@ -34,15 +34,15 @@ class CCMTLGPUPipelineLayout; class CCMTLPipelineLayout final : public PipelineLayout { public: - CCMTLPipelineLayout(Device *device); + CCMTLPipelineLayout(); virtual ~CCMTLPipelineLayout() = default; - virtual bool initialize(const PipelineLayoutInfo &info) override; - virtual void destroy() override; - CC_INLINE CCMTLGPUPipelineLayout *gpuPipelineLayout() const { return _gpuPipelineLayout; } -private: +protected: + void doInit(const PipelineLayoutInfo &info) override; + void doDestroy() override; + CCMTLGPUPipelineLayout *_gpuPipelineLayout = nullptr; }; } // namespace gfx diff --git a/native/cocos/renderer/gfx-metal/MTLPipelineLayout.mm b/native/cocos/renderer/gfx-metal/MTLPipelineLayout.mm index e91bb3b26b..2e39baf658 100644 --- a/native/cocos/renderer/gfx-metal/MTLPipelineLayout.mm +++ b/native/cocos/renderer/gfx-metal/MTLPipelineLayout.mm @@ -31,11 +31,10 @@ namespace cc { namespace gfx { -CCMTLPipelineLayout::CCMTLPipelineLayout(Device *device) : PipelineLayout(device) { +CCMTLPipelineLayout::CCMTLPipelineLayout() : PipelineLayout() { } -bool CCMTLPipelineLayout::initialize(const PipelineLayoutInfo &info) { - _setLayouts = info.setLayouts; +void CCMTLPipelineLayout::doInit(const PipelineLayoutInfo &info) { const auto setCount = _setLayouts.size(); _gpuPipelineLayout = CC_NEW(CCMTLGPUPipelineLayout); _gpuPipelineLayout->dynamicOffsetIndices.resize(setCount); @@ -54,11 +53,9 @@ bool CCMTLPipelineLayout::initialize(const PipelineLayoutInfo &info) { } _gpuPipelineLayout->setLayouts.emplace_back(gpuDescriptorSetLayout); } - - return true; } -void CCMTLPipelineLayout::destroy() { +void CCMTLPipelineLayout::doDestroy() { CC_SAFE_DELETE(_gpuPipelineLayout); } diff --git a/native/cocos/renderer/gfx-metal/MTLPipelineState.h b/native/cocos/renderer/gfx-metal/MTLPipelineState.h index 142082bf72..d776249a4f 100644 --- a/native/cocos/renderer/gfx-metal/MTLPipelineState.h +++ b/native/cocos/renderer/gfx-metal/MTLPipelineState.h @@ -37,19 +37,19 @@ namespace gfx { class CCMTLPipelineState final : public PipelineState { public: - explicit CCMTLPipelineState(Device *device); + explicit CCMTLPipelineState(); ~CCMTLPipelineState() override = default; CCMTLPipelineState(const CCMTLPipelineState &)=delete; CCMTLPipelineState(CCMTLPipelineState &&)=delete; CCMTLPipelineState &operator=(const CCMTLPipelineState &)=delete; CCMTLPipelineState &operator=(CCMTLPipelineState &&)=delete; - bool initialize(const PipelineStateInfo &info) override; - void destroy() override; - CC_INLINE CCMTLGPUPipelineState *getGPUPipelineState() const { return _GPUPipelineState; } -private: +protected: + void doInit(const PipelineStateInfo &info) override; + void doDestroy() override; + bool createMTLDepthStencilState(); bool createGPUPipelineState(); bool createMTLRenderPipelineState(); @@ -59,7 +59,6 @@ private: void setBlendStates(MTLRenderPipelineDescriptor *); bool createMTLRenderPipeline(MTLRenderPipelineDescriptor *); -private: id _mtlRenderPipelineState = nil; id _mtlDepthStencilState = nil; CCMTLGPUPipelineState *_GPUPipelineState = nullptr; diff --git a/native/cocos/renderer/gfx-metal/MTLPipelineState.mm b/native/cocos/renderer/gfx-metal/MTLPipelineState.mm index 9ccbb4ccde..acea665b3c 100644 --- a/native/cocos/renderer/gfx-metal/MTLPipelineState.mm +++ b/native/cocos/renderer/gfx-metal/MTLPipelineState.mm @@ -40,27 +40,13 @@ namespace cc { namespace gfx { -CCMTLPipelineState::CCMTLPipelineState(Device *device) : PipelineState(device) {} +CCMTLPipelineState::CCMTLPipelineState() : PipelineState() {} -bool CCMTLPipelineState::initialize(const PipelineStateInfo &info) { - _primitive = info.primitive; - _shader = info.shader; - _inputState = info.inputState; - _rasterizerState = info.rasterizerState; - _depthStencilState = info.depthStencilState; - _bindPoint = info.bindPoint; - _blendState = info.blendState; - _dynamicStates = info.dynamicStates; - _renderPass = info.renderPass; - _pipelineLayout = info.pipelineLayout; - - if (!createGPUPipelineState()) { - return false; - } - return true; +void CCMTLPipelineState::doInit(const PipelineStateInfo &info) { + createGPUPipelineState(); } -void CCMTLPipelineState::destroy() { +void CCMTLPipelineState::doDestroy() { CC_SAFE_DELETE(_GPUPipelineState); id renderPipelineState = _mtlRenderPipelineState; @@ -142,7 +128,7 @@ bool CCMTLPipelineState::createMTLDepthStencilState() { descriptor.backFaceStencil = nil; } - id mtlDevice = id(static_cast(_device)->getMTLDevice()); + id mtlDevice = id(CCMTLDevice::getInstance()->getMTLDevice()); _mtlDepthStencilState = [mtlDevice newDepthStencilStateWithDescriptor:descriptor]; [descriptor release]; @@ -175,7 +161,7 @@ void CCMTLPipelineState::setVertexDescriptor(MTLRenderPipelineDescriptor *descri vector> layouts; unordered_map> map; - vector streamOffsets(_device->getCapabilities().maxVertexAttributes, 0u); + vector streamOffsets(CCMTLDevice::getInstance()->getCapabilities().maxVertexAttributes, 0u); vector activeAttribIdx(activeAttributes.size(), false); for (const auto &inputAttrib : _inputState.attributes) { auto bufferIndex = static_cast(_shader)->getAvailableBufferBindingIndex(ShaderStageFlagBit::VERTEX, inputAttrib.stream); @@ -274,7 +260,7 @@ void CCMTLPipelineState::setBlendStates(MTLRenderPipelineDescriptor *descriptor) } bool CCMTLPipelineState::createMTLRenderPipeline(MTLRenderPipelineDescriptor *descriptor) { - id mtlDevice = id(((CCMTLDevice *)_device)->getMTLDevice()); + id mtlDevice = id(CCMTLDevice::getInstance()->getMTLDevice()); NSError *nsError = nil; _mtlRenderPipelineState = [mtlDevice newRenderPipelineStateWithDescriptor:descriptor error:&nsError]; if (!_mtlRenderPipelineState) { diff --git a/native/cocos/renderer/gfx-metal/MTLQueue.h b/native/cocos/renderer/gfx-metal/MTLQueue.h index 014314103a..8934c1b2b1 100644 --- a/native/cocos/renderer/gfx-metal/MTLQueue.h +++ b/native/cocos/renderer/gfx-metal/MTLQueue.h @@ -34,18 +34,19 @@ class CCMTLQueue final : public Queue { friend class CCMTLDevice; public: - explicit CCMTLQueue(Device *device); + explicit CCMTLQueue(); ~CCMTLQueue() override = default; CCMTLQueue(const CCMTLQueue &)=delete; CCMTLQueue(CCMTLQueue &&)=delete; CCMTLQueue &operator=(const CCMTLQueue &)=delete; CCMTLQueue &operator=(CCMTLQueue &&)=delete; - bool initialize(const QueueInfo &info) override; - void destroy() override; void submit(CommandBuffer *const *cmdBuffs, uint count) override; -private: +protected: + void doInit(const QueueInfo &info) override; + void doDestroy() override; + uint _numDrawCalls = 0; uint _numInstances = 0; uint _numTriangles = 0; diff --git a/native/cocos/renderer/gfx-metal/MTLQueue.mm b/native/cocos/renderer/gfx-metal/MTLQueue.mm index 700d613391..830cd88f41 100644 --- a/native/cocos/renderer/gfx-metal/MTLQueue.mm +++ b/native/cocos/renderer/gfx-metal/MTLQueue.mm @@ -32,17 +32,14 @@ namespace cc { namespace gfx { -CCMTLQueue::CCMTLQueue(Device *device) -: Queue(device) { +CCMTLQueue::CCMTLQueue() +: Queue() { } -bool CCMTLQueue::initialize(const QueueInfo &info) { - _type = info.type; - - return true; +void CCMTLQueue::doInit(const QueueInfo &info) { } -void CCMTLQueue::destroy() { +void CCMTLQueue::doDestroy() { } void CCMTLQueue::submit(CommandBuffer *const *cmdBuffs, uint count) { @@ -60,7 +57,7 @@ void CCMTLQueue::submit(CommandBuffer *const *cmdBuffs, uint count) { } else { // Must do present before commit last command buffer. - CCMTLDevice* device = (CCMTLDevice*)_device; + CCMTLDevice* device = (CCMTLDevice*)CCMTLDevice::getInstance(); id currDrawable = (id)device->getCurrentDrawable(); [mtlCmdBuffer presentDrawable:currDrawable]; [mtlCmdBuffer addCompletedHandler:^(id commandBuffer) { diff --git a/native/cocos/renderer/gfx-metal/MTLRenderCommandEncoder.h b/native/cocos/renderer/gfx-metal/MTLRenderCommandEncoder.h index b2b15a3ef1..4c92830cfe 100644 --- a/native/cocos/renderer/gfx-metal/MTLRenderCommandEncoder.h +++ b/native/cocos/renderer/gfx-metal/MTLRenderCommandEncoder.h @@ -274,7 +274,7 @@ public: return _mtlEncoder; } -private: +protected: bool _isViewportSet = false; bool _isScissorRectSet = false; bool _isCullModeSet = false; diff --git a/native/cocos/renderer/gfx-metal/MTLRenderPass.h b/native/cocos/renderer/gfx-metal/MTLRenderPass.h index b8f89181be..82cf9488b1 100644 --- a/native/cocos/renderer/gfx-metal/MTLRenderPass.h +++ b/native/cocos/renderer/gfx-metal/MTLRenderPass.h @@ -37,12 +37,9 @@ namespace gfx { class CCMTLRenderPass final : public RenderPass { public: - explicit CCMTLRenderPass(Device *device); + explicit CCMTLRenderPass(); ~CCMTLRenderPass() override = default; - bool initialize(const RenderPassInfo &info) override; - void destroy() override; - void setColorAttachment(size_t slot, id texture, int level); void setDepthStencilAttachment(id texture, int level); @@ -50,7 +47,10 @@ public: CC_INLINE uint getColorRenderTargetNums() const { return _colorRenderTargetNums; } CC_INLINE const vector &getRenderTargetSizes() const { return _renderTargetSizes; } -private: +protected: + void doInit(const RenderPassInfo &info) override; + void doDestroy() override; + MTLRenderPassDescriptor *_mtlRenderPassDescriptor = nil; uint _colorRenderTargetNums = 0; vector _renderTargetSizes; diff --git a/native/cocos/renderer/gfx-metal/MTLRenderPass.mm b/native/cocos/renderer/gfx-metal/MTLRenderPass.mm index 66dbadd782..4e4a6b9b38 100644 --- a/native/cocos/renderer/gfx-metal/MTLRenderPass.mm +++ b/native/cocos/renderer/gfx-metal/MTLRenderPass.mm @@ -32,13 +32,10 @@ namespace cc { namespace gfx { -CCMTLRenderPass::CCMTLRenderPass(Device *device) : RenderPass(device) {} +CCMTLRenderPass::CCMTLRenderPass() : RenderPass() {} -bool CCMTLRenderPass::initialize(const RenderPassInfo &info) { - _colorAttachments = info.colorAttachments; - _depthStencilAttachment = info.depthStencilAttachment; +void CCMTLRenderPass::doInit(const RenderPassInfo &info) { _renderTargetSizes.resize(_colorAttachments.size()); - _mtlRenderPassDescriptor = [[MTLRenderPassDescriptor alloc] init]; uint i = 0; @@ -53,13 +50,9 @@ bool CCMTLRenderPass::initialize(const RenderPassInfo &info) { _mtlRenderPassDescriptor.depthAttachment.storeAction = mu::toMTLStoreAction(_depthStencilAttachment.depthStoreOp); _mtlRenderPassDescriptor.stencilAttachment.loadAction = mu::toMTLLoadAction(_depthStencilAttachment.stencilLoadOp); _mtlRenderPassDescriptor.stencilAttachment.storeAction = mu::toMTLStoreAction(_depthStencilAttachment.stencilStoreOp); - - _hash = computeHash(); - - return true; } -void CCMTLRenderPass::destroy() { +void CCMTLRenderPass::doDestroy() { if (_mtlRenderPassDescriptor) { [_mtlRenderPassDescriptor release]; _mtlRenderPassDescriptor = nil; diff --git a/native/cocos/renderer/gfx-metal/MTLSampler.h b/native/cocos/renderer/gfx-metal/MTLSampler.h index 811b2f9f16..bb7f87cf9a 100644 --- a/native/cocos/renderer/gfx-metal/MTLSampler.h +++ b/native/cocos/renderer/gfx-metal/MTLSampler.h @@ -34,19 +34,19 @@ namespace gfx { class CCMTLSampler final : public Sampler { public: - explicit CCMTLSampler(Device *device); + explicit CCMTLSampler(); ~CCMTLSampler() override = default; CCMTLSampler(const CCMTLSampler &)=delete; CCMTLSampler(CCMTLSampler &&)=delete; CCMTLSampler &operator=(const CCMTLSampler &)=delete; CCMTLSampler &operator=(CCMTLSampler &&)=delete; - bool initialize(const SamplerInfo &info) override; - void destroy() override; - CC_INLINE id getMTLSamplerState() const { return _mtlSamplerState; } -private: +protected: + void doInit(const SamplerInfo &info) override; + void doDestroy() override; + id _mtlSamplerState = nil; }; diff --git a/native/cocos/renderer/gfx-metal/MTLSampler.mm b/native/cocos/renderer/gfx-metal/MTLSampler.mm index 452979a852..7b887b6c6e 100644 --- a/native/cocos/renderer/gfx-metal/MTLSampler.mm +++ b/native/cocos/renderer/gfx-metal/MTLSampler.mm @@ -34,20 +34,9 @@ namespace cc { namespace gfx { -CCMTLSampler::CCMTLSampler(Device *device) : Sampler(device) {} - -bool CCMTLSampler::initialize(const SamplerInfo &info) { - _minFilter = info.minFilter; - _magFilter = info.magFilter; - _mipFilter = info.mipFilter; - _addressU = info.addressU; - _addressV = info.addressV; - _addressW = info.addressW; - _maxAnisotropy = info.maxAnisotropy; - _cmpFunc = info.cmpFunc; - _borderColor = info.borderColor; - _mipLODBias = info.mipLODBias; +CCMTLSampler::CCMTLSampler() : Sampler() {} +void CCMTLSampler::doInit(const SamplerInfo &info) { MTLSamplerDescriptor *descriptor = [[MTLSamplerDescriptor alloc] init]; #if (CC_PLATFORM == CC_PLATFORM_MAC_OSX) descriptor.borderColor = (MTLSamplerBorderColor)mu::toMTLSamplerBorderColor(_borderColor); @@ -59,19 +48,17 @@ bool CCMTLSampler::initialize(const SamplerInfo &info) { descriptor.magFilter = mu::toMTLSamplerMinMagFilter(_magFilter); descriptor.mipFilter = mu::toMTLSamplerMipFilter(_mipFilter); descriptor.maxAnisotropy = _maxAnisotropy == 0 ? 1 : _maxAnisotropy; - if (static_cast(_device)->isSamplerDescriptorCompareFunctionSupported()) { + if (CCMTLDevice::getInstance()->isSamplerDescriptorCompareFunctionSupported()) { descriptor.compareFunction = mu::toMTLCompareFunction(_cmpFunc); } - id mtlDevice = id(static_cast(_device)->getMTLDevice()); + id mtlDevice = id(CCMTLDevice::getInstance()->getMTLDevice()); _mtlSamplerState = [mtlDevice newSamplerStateWithDescriptor:descriptor]; [descriptor release]; - - return _mtlSamplerState != nil; } -void CCMTLSampler::destroy() { +void CCMTLSampler::doDestroy() { id samplerState = _mtlSamplerState; _mtlSamplerState = nil; diff --git a/native/cocos/renderer/gfx-metal/MTLSemaphore.h b/native/cocos/renderer/gfx-metal/MTLSemaphore.h index b00ce0a505..8222071342 100644 --- a/native/cocos/renderer/gfx-metal/MTLSemaphore.h +++ b/native/cocos/renderer/gfx-metal/MTLSemaphore.h @@ -55,7 +55,7 @@ public: } } -private: +protected: dispatch_semaphore_t _semaphore = nullptr; uint _semaphoreCount = 0; }; diff --git a/native/cocos/renderer/gfx-metal/MTLShader.h b/native/cocos/renderer/gfx-metal/MTLShader.h index 6c088ecea8..b87cb7051e 100644 --- a/native/cocos/renderer/gfx-metal/MTLShader.h +++ b/native/cocos/renderer/gfx-metal/MTLShader.h @@ -34,16 +34,13 @@ namespace gfx { class CCMTLGPUShader; class CCMTLShader final : public Shader { public: - explicit CCMTLShader(Device *device); + explicit CCMTLShader(); ~CCMTLShader() override = default; CCMTLShader(const CCMTLShader &)=delete; CCMTLShader(CCMTLShader &&)=delete; CCMTLShader &operator=(const CCMTLShader &)=delete; CCMTLShader &operator=(CCMTLShader &&)=delete; - bool initialize(const ShaderInfo &info) override; - void destroy() override; - CC_INLINE id getVertMTLFunction() const { return _vertexMTLFunction; } CC_INLINE id getFragmentMTLFunction() const { return _fragmentMTLFunction; } CC_INLINE const unordered_map &getFragmentSamplerBindings() const { return _mtlFragmentSamplerBindings; } @@ -58,11 +55,13 @@ public: CC_INLINE const String &getFragMtlSahder() const { return _fragMtlShader; } #endif -private: +protected: + void doInit(const ShaderInfo &info) override; + void doDestroy() override; + bool createMTLFunction(const ShaderStage &); void setAvailableBufferBindingIndex(); -private: id _vertexMTLFunction = nil; id _fragmentMTLFunction = nil; unordered_map _mtlFragmentSamplerBindings; diff --git a/native/cocos/renderer/gfx-metal/MTLShader.mm b/native/cocos/renderer/gfx-metal/MTLShader.mm index a908f78222..5a4a96aec0 100644 --- a/native/cocos/renderer/gfx-metal/MTLShader.mm +++ b/native/cocos/renderer/gfx-metal/MTLShader.mm @@ -33,15 +33,9 @@ namespace cc { namespace gfx { -CCMTLShader::CCMTLShader(Device *device) : Shader(device) {} - -bool CCMTLShader::initialize(const ShaderInfo &info) { - _name = info.name; - _stages = info.stages; - _attributes = info.attributes; - _blocks = info.blocks; - _samplers = info.samplers; +CCMTLShader::CCMTLShader() : Shader() {} +void CCMTLShader::doInit(const ShaderInfo &info) { _gpuShader = CC_NEW(CCMTLGPUShader); for (const auto &stage : _stages) { @@ -54,10 +48,9 @@ bool CCMTLShader::initialize(const ShaderInfo &info) { setAvailableBufferBindingIndex(); CC_LOG_INFO("%s compile succeed.", _name.c_str()); - return true; } -void CCMTLShader::destroy() { +void CCMTLShader::doDestroy() { id vertFunc = _vertexMTLFunction; _vertexMTLFunction = nil; id fragFunc = _fragmentMTLFunction; @@ -78,10 +71,10 @@ void CCMTLShader::destroy() { bool CCMTLShader::createMTLFunction(const ShaderStage &stage) { bool isVertexShader = stage.stage == ShaderStageFlagBit::VERTEX; - id mtlDevice = id(static_cast(_device)->getMTLDevice()); + id mtlDevice = id(CCMTLDevice::getInstance()->getMTLDevice()); auto mtlShader = mu::compileGLSLShader2Msl(stage.source, stage.stage, - _device, + CCMTLDevice::getInstance(), _gpuShader); NSString *shader = [NSString stringWithUTF8String:mtlShader.c_str()]; @@ -155,7 +148,7 @@ void CCMTLShader::setAvailableBufferBindingIndex() { } } - auto maxBufferBindingIndex = static_cast(_device)->getMaximumBufferBindingIndex(); + auto maxBufferBindingIndex = CCMTLDevice::getInstance()->getMaximumBufferBindingIndex(); _availableVertexBufferBindingIndex.resize(maxBufferBindingIndex - vertexBindingCount); _availableFragmentBufferBindingIndex.resize(maxBufferBindingIndex - fragmentBindingCount); uint availableVertexBufferBit = ~usedVertexBufferBindingIndexes; diff --git a/native/cocos/renderer/gfx-metal/MTLTexture.h b/native/cocos/renderer/gfx-metal/MTLTexture.h index 7c21de3cb4..4a6e0c0dc7 100644 --- a/native/cocos/renderer/gfx-metal/MTLTexture.h +++ b/native/cocos/renderer/gfx-metal/MTLTexture.h @@ -34,27 +34,26 @@ namespace gfx { class CCMTLTexture final : public Texture { public: - explicit CCMTLTexture(Device *device); + explicit CCMTLTexture(); ~CCMTLTexture() override = default; CCMTLTexture(const CCMTLTexture &) = delete; CCMTLTexture(CCMTLTexture &&) = delete; CCMTLTexture &operator=(const CCMTLTexture &) = delete; CCMTLTexture &operator=(CCMTLTexture &&) = delete; - bool initialize(const TextureInfo &info) override; - bool initialize(const TextureViewInfo &info) override; - void destroy() override; - void resize(uint width, uint height) override; - CC_INLINE id getMTLTexture() const { return _mtlTexture; } CC_INLINE Format getConvertedFormat() const { return _convertedFormat; } CC_INLINE bool isArray() const { return _isArray; } CC_INLINE bool isPVRTC() const { return _isPVRTC; } -private: +protected: + void doInit(const TextureInfo &info) override; + void doInit(const TextureViewInfo &info) override; + void doDestroy() override; + void doResize(uint width, uint height) override; + bool createMTLTexture(); -private: id _mtlTexture = nil; Format _convertedFormat = Format::UNKNOWN; bool _isArray = false; diff --git a/native/cocos/renderer/gfx-metal/MTLTexture.mm b/native/cocos/renderer/gfx-metal/MTLTexture.mm index 294d0cbb25..4e6df7af43 100644 --- a/native/cocos/renderer/gfx-metal/MTLTexture.mm +++ b/native/cocos/renderer/gfx-metal/MTLTexture.mm @@ -33,20 +33,9 @@ namespace cc { namespace gfx { -CCMTLTexture::CCMTLTexture(Device *device) : Texture(device) {} +CCMTLTexture::CCMTLTexture() : Texture() {} -bool CCMTLTexture::initialize(const TextureInfo &info) { - _type = info.type; - _usage = info.usage; - _format = info.format; - _width = info.width; - _height = info.height; - _depth = info.depth; - _layerCount = info.layerCount; - _levelCount = info.levelCount; - _samples = info.samples; - _flags = info.flags; - _size = FormatSize(_format, _width, _height, _depth); +void CCMTLTexture::doInit(const TextureInfo &info) { _isArray = _type == TextureType::TEX1D_ARRAY || _type == TextureType::TEX2D_ARRAY; if (_format == Format::PVRTC_RGB2 || _format == Format::PVRTC_RGBA2 || @@ -57,77 +46,13 @@ bool CCMTLTexture::initialize(const TextureInfo &info) { _isPVRTC = true; } -#if CC_DEBUG > 0 - switch (_format) { // device feature validation - case Format::D16: - if (_device->hasFeature(Feature::FORMAT_D16)) break; - CC_LOG_ERROR("D16 texture format is not supported on this backend"); - return false; - case Format::D16S8: - if (_device->hasFeature(Feature::FORMAT_D16S8)) break; - CC_LOG_WARNING("D16S8 texture format is not supported on this backend"); - return false; - case Format::D24: - if (_device->hasFeature(Feature::FORMAT_D24)) break; - CC_LOG_WARNING("D24 texture format is not supported on this backend"); - return false; - case Format::D24S8: - if (_device->hasFeature(Feature::FORMAT_D24S8)) break; - CC_LOG_WARNING("D24S8 texture format is not supported on this backend"); - return false; - case Format::D32F: - if (_device->hasFeature(Feature::FORMAT_D32F)) break; - CC_LOG_WARNING("D32F texture format is not supported on this backend"); - return false; - case Format::D32F_S8: - if (_device->hasFeature(Feature::FORMAT_D32FS8)) break; - CC_LOG_WARNING("D32FS8 texture format is not supported on this backend"); - return false; - case Format::RGB8: - if (_device->hasFeature(Feature::FORMAT_RGB8)) break; - CC_LOG_WARNING("RGB8 texture format is not supported on this backend"); - return false; - default: - break; - } -#endif - - if (_flags & TextureFlags::BAKUP_BUFFER) { - _buffer = (uint8_t *)CC_MALLOC(_size); - if (!_buffer) { - CC_LOG_ERROR("CCMTLTexture: CC_MALLOC backup buffer failed."); - return false; - } - _device->getMemoryStatus().textureSize += _size; - } - if (!createMTLTexture()) { CC_LOG_ERROR("CCMTLTexture: create MTLTexture failed."); - return false; + return; } - - _device->getMemoryStatus().textureSize += _size; - return true; } -bool CCMTLTexture::initialize(const TextureViewInfo &info) { - _isTextureView = true; - - if (!info.texture) { - return false; - } - - _type = info.type; - _usage = info.texture->getUsage(); - _format = info.format; - _width = info.texture->getWidth(); - _height = info.texture->getHeight(); - _depth = info.texture->getDepth(); - _layerCount = info.texture->getLayerCount(); - _levelCount = info.texture->getLevelCount(); - _samples = info.texture->getSamples(); - _flags = info.texture->getFlags(); - _size = info.texture->getSize(); +void CCMTLTexture::doInit(const TextureViewInfo &info) { _isArray = _type == TextureType::TEX1D_ARRAY || _type == TextureType::TEX2D_ARRAY; if (_format == Format::PVRTC_RGB2 || _format == Format::PVRTC_RGBA2 || @@ -143,11 +68,6 @@ bool CCMTLTexture::initialize(const TextureViewInfo &info) { textureType:mtlTextureType levels:NSMakeRange(info.baseLevel, info.levelCount) slices:NSMakeRange(info.baseLayer, info.layerCount)]; - if (!_mtlTexture) { - return false; - } - - return true; } bool CCMTLTexture::createMTLTexture() { @@ -196,42 +116,30 @@ bool CCMTLTexture::createMTLTexture() { descriptor.resourceOptions = MTLResourceStorageModePrivate; } - id mtlDevice = id(static_cast(_device)->getMTLDevice()); + id mtlDevice = id(CCMTLDevice::getInstance()->getMTLDevice()); _mtlTexture = [mtlDevice newTextureWithDescriptor:descriptor]; return _mtlTexture != nil; } -void CCMTLTexture::destroy() { +void CCMTLTexture::doDestroy() { if (_isTextureView) { return; } - if (_buffer) { - CC_FREE(_buffer); - _device->getMemoryStatus().textureSize -= _size; - _buffer = nullptr; - } - - Device *device = _device; id mtlTexure = _mtlTexture; _mtlTexture = nil; - uint size = _size; std::function destroyFunc = [=]() { if (mtlTexure) { [mtlTexure release]; - device->getMemoryStatus().textureSize -= size; } }; //gpu object only CCMTLGPUGarbageCollectionPool::getInstance()->collect(destroyFunc); } -void CCMTLTexture::resize(uint width, uint height) { - if (_width == width && _height == height) - return; - +void CCMTLTexture::doResize(uint width, uint height) { auto oldSize = _size; auto oldWidth = _width; auto oldHeight = _height; @@ -250,32 +158,15 @@ void CCMTLTexture::resize(uint width, uint height) { } if (oldMTLTexture) { - Device *device = _device; std::function destroyFunc = [=]() { if (oldMTLTexture) { [oldMTLTexture release]; - device->getMemoryStatus().bufferSize -= oldSize; } }; //gpu object only CCMTLGPUGarbageCollectionPool::getInstance()->collect(destroyFunc); } - - _device->getMemoryStatus().textureSize -= oldSize; - if (_flags & TextureFlags::BAKUP_BUFFER) { - const uint8_t *oldBuffer = _buffer; - uint8_t *buffer = (uint8_t *)CC_MALLOC(_size); - if (!buffer) { - CC_LOG_ERROR("CCMTLTexture: CC_MALLOC backup buffer failed when try to resize the texture."); - return; - } - CC_FREE(oldBuffer); - _buffer = buffer; - _device->getMemoryStatus().textureSize -= oldSize; - _device->getMemoryStatus().textureSize += _size; - } - - _device->getMemoryStatus().textureSize += _size; } + } // namespace gfx } // namespace cc diff --git a/native/cocos/renderer/gfx-vulkan/GFXVulkan.h b/native/cocos/renderer/gfx-vulkan/GFXVulkan.h index 06cc8a04b6..902bf7163a 100644 --- a/native/cocos/renderer/gfx-vulkan/GFXVulkan.h +++ b/native/cocos/renderer/gfx-vulkan/GFXVulkan.h @@ -23,11 +23,8 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_VK_H_ -#define CC_GFXVULKAN_VK_H_ +#pragma once #include "VKStd.h" #include "VKDevice.h" - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp index 5ad7fa6ffb..f7654273dd 100644 --- a/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKBuffer.cpp @@ -33,21 +33,14 @@ namespace cc { namespace gfx { -CCVKBuffer::CCVKBuffer(Device *device) -: Buffer(device) { +CCVKBuffer::CCVKBuffer() +: Buffer() { } CCVKBuffer::~CCVKBuffer() { } -bool CCVKBuffer::initialize(const BufferInfo &info) { - _usage = info.usage; - _memUsage = info.memUsage; - _size = info.size; - _stride = std::max(info.stride, 1u); - _count = _size / _stride; - _flags = info.flags; - +void CCVKBuffer::doInit(const BufferInfo &info) { _gpuBuffer = CC_NEW(CCVKGPUBuffer); _gpuBuffer->usage = _usage; _gpuBuffer->memUsage = _memUsage; @@ -61,91 +54,62 @@ bool CCVKBuffer::initialize(const BufferInfo &info) { _gpuBuffer->indirectCmds.resize(drawInfoCount); } - CCVKCmdFuncCreateBuffer((CCVKDevice *)_device, _gpuBuffer); - _device->getMemoryStatus().bufferSize += _size; + CCVKCmdFuncCreateBuffer(CCVKDevice::getInstance(), _gpuBuffer); _gpuBufferView = CC_NEW(CCVKGPUBufferView); createBufferView(); - - return true; } -bool CCVKBuffer::initialize(const BufferViewInfo &info) { - _isBufferView = true; - +void CCVKBuffer::doInit(const BufferViewInfo &info) { CCVKBuffer *buffer = (CCVKBuffer *)info.buffer; - - _usage = buffer->_usage; - _memUsage = buffer->_memUsage; - _size = _stride = info.range; - _count = 1u; - _flags = buffer->_flags; - _offset = info.offset; - - _gpuBuffer = ((CCVKBuffer *)info.buffer)->gpuBuffer(); + _gpuBuffer = buffer->gpuBuffer(); _gpuBufferView = CC_NEW(CCVKGPUBufferView); createBufferView(); - - return true; } void CCVKBuffer::createBufferView() { _gpuBufferView->gpuBuffer = _gpuBuffer; _gpuBufferView->offset = _offset; _gpuBufferView->range = _size; - ((CCVKDevice *)_device)->gpuDescriptorHub()->update(_gpuBufferView); + CCVKDevice::getInstance()->gpuDescriptorHub()->update(_gpuBufferView); } -void CCVKBuffer::destroy() { +void CCVKBuffer::doDestroy() { if (_gpuBufferView) { - ((CCVKDevice *)_device)->gpuDescriptorHub()->disengage(_gpuBufferView); + CCVKDevice::getInstance()->gpuDescriptorHub()->disengage(_gpuBufferView); CC_DELETE(_gpuBufferView); _gpuBufferView = nullptr; } if (_gpuBuffer) { if (!_isBufferView) { - ((CCVKDevice *)_device)->gpuBufferHub()->erase(_gpuBuffer); - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuBuffer); - ((CCVKDevice *)_device)->gpuBarrierManager()->cancel(_gpuBuffer); - _device->getMemoryStatus().bufferSize -= _size; + CCVKDevice::getInstance()->gpuBufferHub()->erase(_gpuBuffer); + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuBuffer); + CCVKDevice::getInstance()->gpuBarrierManager()->cancel(_gpuBuffer); CC_DELETE(_gpuBuffer); } _gpuBuffer = nullptr; } } -void CCVKBuffer::resize(uint size) { - CCASSERT(!_isBufferView, "Cannot resize buffer views"); +void CCVKBuffer::doResize(uint size) { + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuBuffer); - if (_size != size) { - const uint oldSize = _size; - _size = size; - _count = _size / _stride; + _gpuBuffer->size = _size; + _gpuBuffer->count = _count; + CCVKCmdFuncCreateBuffer(CCVKDevice::getInstance(), _gpuBuffer); - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuBuffer); + createBufferView(); - _gpuBuffer->size = _size; - _gpuBuffer->count = _count; - CCVKCmdFuncCreateBuffer((CCVKDevice *)_device, _gpuBuffer); - - createBufferView(); - - MemoryStatus &status = _device->getMemoryStatus(); - status.bufferSize -= oldSize; - status.bufferSize += _size; - - if (_usage & BufferUsageBit::INDIRECT) { - const size_t drawInfoCount = _size / sizeof(DrawInfo); - _gpuBuffer->indexedIndirectCmds.resize(drawInfoCount); - _gpuBuffer->indirectCmds.resize(drawInfoCount); - } + if (_usage & BufferUsageBit::INDIRECT) { + const size_t drawInfoCount = _size / sizeof(DrawInfo); + _gpuBuffer->indexedIndirectCmds.resize(drawInfoCount); + _gpuBuffer->indirectCmds.resize(drawInfoCount); } } void CCVKBuffer::update(void *buffer, uint size) { CCASSERT(!_isBufferView, "Cannot update through buffer views"); - if (!size) return; #if CC_DEBUG > 0 if (_usage & BufferUsageBit::INDIRECT) { @@ -161,12 +125,8 @@ void CCVKBuffer::update(void *buffer, uint size) { } #endif - if (_buffer) { - memcpy(_buffer, buffer, size); - } - - ((CCVKDevice *)_device)->gpuTransportHub()->checkIn([this, buffer, size](CCVKGPUCommandBuffer *gpuCommandBuffer) { - CCVKCmdFuncUpdateBuffer((CCVKDevice *)_device, _gpuBuffer, buffer, size, gpuCommandBuffer); + CCVKDevice::getInstance()->gpuTransportHub()->checkIn([this, buffer, size](CCVKGPUCommandBuffer *gpuCommandBuffer) { + CCVKCmdFuncUpdateBuffer(CCVKDevice::getInstance(), _gpuBuffer, buffer, size, gpuCommandBuffer); }); } diff --git a/native/cocos/renderer/gfx-vulkan/VKBuffer.h b/native/cocos/renderer/gfx-vulkan/VKBuffer.h index 100504a240..4db6d44e1e 100644 --- a/native/cocos/renderer/gfx-vulkan/VKBuffer.h +++ b/native/cocos/renderer/gfx-vulkan/VKBuffer.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_BUFFER_H_ -#define CC_GFXVULKAN_BUFFER_H_ +#pragma once #include "gfx-base/GFXBuffer.h" @@ -36,20 +35,20 @@ class CCVKGPUBufferView; class CC_VULKAN_API CCVKBuffer final : public Buffer { public: - CCVKBuffer(Device *device); + CCVKBuffer(); ~CCVKBuffer(); -public: - bool initialize(const BufferInfo &info); - bool initialize(const BufferViewInfo &info); - void destroy(); - void resize(uint size); - void update(void *buffer, uint offset); + void update(void *buffer, uint offset) override; CC_INLINE CCVKGPUBuffer *gpuBuffer() const { return _gpuBuffer; } CC_INLINE CCVKGPUBufferView *gpuBufferView() const { return _gpuBufferView; } -private: +protected: + void doInit(const BufferInfo &info) override; + void doInit(const BufferViewInfo &info) override; + void doDestroy() override; + void doResize(uint size) override; + void createBufferView(); CCVKGPUBuffer *_gpuBuffer = nullptr; @@ -58,5 +57,3 @@ private: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp index 434dd50a6b..69fb3ef67d 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp @@ -43,31 +43,26 @@ namespace cc { namespace gfx { -CCVKCommandBuffer::CCVKCommandBuffer(Device *device) -: CommandBuffer(device) { +CCVKCommandBuffer::CCVKCommandBuffer() +: CommandBuffer() { } CCVKCommandBuffer::~CCVKCommandBuffer() { } -bool CCVKCommandBuffer::initialize(const CommandBufferInfo &info) { - _type = info.type; - _queue = info.queue; - +void CCVKCommandBuffer::doInit(const CommandBufferInfo &info) { _gpuCommandBuffer = CC_NEW(CCVKGPUCommandBuffer); _gpuCommandBuffer->level = MapVkCommandBufferLevel(_type); _gpuCommandBuffer->queueFamilyIndex = ((CCVKQueue *)_queue)->gpuQueue()->queueFamilyIndex; - size_t setCount = ((CCVKDevice *)_device)->bindingMappingInfo().bufferOffsets.size(); + size_t setCount = CCVKDevice::getInstance()->bindingMappingInfo().bufferOffsets.size(); _curGPUDescriptorSets.resize(setCount); _curVkDescriptorSets.resize(setCount); _curDynamicOffsetPtrs.resize(setCount); _curDynamicOffsetCounts.resize(setCount); - - return true; } -void CCVKCommandBuffer::destroy() { +void CCVKCommandBuffer::doDestroy() { if (_gpuCommandBuffer) { CC_DELETE(_gpuCommandBuffer); _gpuCommandBuffer = nullptr; @@ -77,7 +72,7 @@ void CCVKCommandBuffer::destroy() { void CCVKCommandBuffer::begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) { if (_gpuCommandBuffer->began) return; - ((CCVKDevice *)_device)->gpuDevice()->getCommandBufferPool()->request(_gpuCommandBuffer); + CCVKDevice::getInstance()->gpuDevice()->getCommandBufferPool()->request(_gpuCommandBuffer); _curGPUPipelineState = nullptr; _curGPUInputAssember = nullptr; @@ -127,7 +122,7 @@ void CCVKCommandBuffer::end() { _gpuCommandBuffer->began = false; _pendingQueue.push(_gpuCommandBuffer->vkCommandBuffer); - ((CCVKDevice *)_device)->gpuDevice()->getCommandBufferPool()->yield(_gpuCommandBuffer); + CCVKDevice::getInstance()->gpuDevice()->getCommandBufferPool()->yield(_gpuCommandBuffer); } void CCVKCommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, @@ -352,7 +347,7 @@ void CCVKCommandBuffer::draw(InputAssembler *ia) { if (gpuIndirectBuffer) { uint drawInfoCount = gpuIndirectBuffer->count; - CCVKGPUDevice *gpuDevice = static_cast(_device)->gpuDevice(); + CCVKGPUDevice *gpuDevice = CCVKDevice::getInstance()->gpuDevice(); VkDeviceSize offset = gpuIndirectBuffer->startOffset + gpuDevice->curBackBufferIndex * gpuIndirectBuffer->instanceSize; if (gpuDevice->useMultiDrawIndirect) { if (gpuIndirectBuffer->isDrawIndirectByIndex) { @@ -442,11 +437,11 @@ void CCVKCommandBuffer::execute(CommandBuffer *const *cmdBuffs, uint count) { void CCVKCommandBuffer::updateBuffer(Buffer *buffer, const void *data, uint size) { CCVKGPUBuffer *gpuBuffer = ((CCVKBuffer *)buffer)->gpuBuffer(); - CCVKCmdFuncUpdateBuffer((CCVKDevice *)_device, gpuBuffer, data, size, _gpuCommandBuffer); + CCVKCmdFuncUpdateBuffer(CCVKDevice::getInstance(), gpuBuffer, data, size, _gpuCommandBuffer); } void CCVKCommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) { - CCVKCmdFuncCopyBuffersToTexture((CCVKDevice *)_device, buffers, ((CCVKTexture *)texture)->gpuTexture(), regions, count, _gpuCommandBuffer); + CCVKCmdFuncCopyBuffersToTexture(CCVKDevice::getInstance(), buffers, ((CCVKTexture *)texture)->gpuTexture(), regions, count, _gpuCommandBuffer); } void CCVKCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) { @@ -456,7 +451,7 @@ void CCVKCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, co VkImage dstImage = VK_NULL_HANDLE; VkImageLayout srcImageLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; VkImageLayout dstImageLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; - CCVKGPUSwapchain * swapchain = ((CCVKDevice *)_device)->gpuSwapchain(); + CCVKGPUSwapchain * swapchain = CCVKDevice::getInstance()->gpuSwapchain(); if (srcTexture) { CCVKGPUTexture *gpuTextureSrc = ((CCVKTexture *)srcTexture)->gpuTexture(); @@ -509,7 +504,7 @@ void CCVKCommandBuffer::blitTexture(Texture *srcTexture, Texture *dstTexture, co } void CCVKCommandBuffer::bindDescriptorSets(VkPipelineBindPoint bindPoint) { - CCVKDevice * device = (CCVKDevice *)_device; + CCVKDevice * device = CCVKDevice::getInstance(); CCVKGPUDevice * gpuDevice = device->gpuDevice(); CCVKGPUPipelineLayout *pipelineLayout = _curGPUPipelineState->gpuPipelineLayout; vector & dynamicOffsetOffsets = pipelineLayout->dynamicOffsetOffsets; @@ -585,7 +580,7 @@ void CCVKCommandBuffer::pipelineBarrier(const GlobalBarrier *barrier, const Text _imageMemoryBarriers[i].subresourceRange.aspectMask = gpuTexture->aspectMask; gpuTexture->currentAccessTypes.assign(gpuBarrier->barrier.pNextAccesses, gpuBarrier->barrier.pNextAccesses + gpuBarrier->barrier.nextAccessCount); } else { - CCVKGPUSwapchain *swapchain = ((CCVKDevice *)_device)->gpuSwapchain(); + CCVKGPUSwapchain *swapchain = CCVKDevice::getInstance()->gpuSwapchain(); _imageMemoryBarriers[i].image = swapchain->swapchainImages[swapchain->curImageIndex]; _imageMemoryBarriers[i].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; swapchain->swapchainImageAccessTypes[swapchain->curImageIndex].assign(gpuBarrier->barrier.pNextAccesses, gpuBarrier->barrier.pNextAccesses + gpuBarrier->barrier.nextAccessCount); diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h index 8c7911eda3..b0de93f42a 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_COMMAND_BUFFER_H_ -#define CC_GFXVULKAN_COMMAND_BUFFER_H_ +#pragma once #include "gfx-base/GFXCommandBuffer.h" @@ -35,41 +34,40 @@ namespace gfx { class CC_VULKAN_API CCVKCommandBuffer final : public CommandBuffer { public: - CCVKCommandBuffer(Device *device); + CCVKCommandBuffer(); ~CCVKCommandBuffer(); - friend class CCVKQueue; - -public: - virtual bool initialize(const CommandBufferInfo &info) override; - virtual void destroy() override; - - virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; - virtual void end() override; - virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; - virtual void endRenderPass() override; - virtual void bindPipelineState(PipelineState *pso) override; - virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; - virtual void bindInputAssembler(InputAssembler *ia) override; - virtual void setViewport(const Viewport &vp) override; - virtual void setScissor(const Rect &rect) override; - virtual void setLineWidth(float width) override; - virtual void setDepthBias(float constant, float clamp, float slope) override; - virtual void setBlendConstants(const Color &constants) override; - virtual void setDepthBound(float minBounds, float maxBounds) override; - virtual void setStencilWriteMask(StencilFace face, uint mask) override; - virtual void setStencilCompareMask(StencilFace face, int reference, uint mask) override; - virtual void draw(InputAssembler *ia) override; - virtual void updateBuffer(Buffer *buffer, const void *data, uint size) override; - virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override; - virtual void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint count, Filter filter) override; - virtual void execute(CommandBuffer *const *cmdBuffs, uint count) override; - virtual void dispatch(const DispatchInfo &info) override; - virtual void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) override; + void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override; + void end() override; + void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil, CommandBuffer *const *secondaryCBs, uint secondaryCBCount) override; + void endRenderPass() override; + void bindPipelineState(PipelineState *pso) override; + void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override; + void bindInputAssembler(InputAssembler *ia) override; + void setViewport(const Viewport &vp) override; + void setScissor(const Rect &rect) override; + void setLineWidth(float width) override; + 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, int reference, uint mask) override; + void draw(InputAssembler *ia) 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 dispatch(const DispatchInfo &info) override; + void pipelineBarrier(const GlobalBarrier *barrier, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint textureBarrierCount) override; CCVKGPUCommandBuffer *gpuCommandBuffer() const { return _gpuCommandBuffer; } -private: +protected: + friend class CCVKQueue; + + void doInit(const CommandBufferInfo &info) override; + void doDestroy() override; + void bindDescriptorSets(VkPipelineBindPoint bindPoint); CCVKGPUCommandBuffer *_gpuCommandBuffer = nullptr; @@ -104,5 +102,3 @@ private: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp index 274dbfe6d5..25bdb8086f 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.cpp @@ -82,7 +82,7 @@ void CCVKCmdFuncGetDeviceQueue(CCVKDevice *device, CCVKGPUQueue *gpuQueue) { case QueueType::TRANSFER: queueType = VK_QUEUE_TRANSFER_BIT; break; } - const CCVKGPUContext *context = ((CCVKContext *)device->getContext())->gpuContext(); + const CCVKGPUContext *context = device->gpuContext(); size_t queueCount = context->queueFamilyProperties.size(); for (size_t i = 0u; i < queueCount; ++i) { @@ -450,7 +450,7 @@ void CCVKCmdFuncCreateFramebuffer(CCVKDevice *device, CCVKGPUFramebuffer *gpuFra void CCVKCmdFuncCreateShader(CCVKDevice *device, CCVKGPUShader *gpuShader) { for (CCVKGPUShaderStage &stage : gpuShader->gpuStages) { - vector spirv = GLSL2SPIRV(stage.type, "#version 450\n" + stage.source, ((CCVKContext *)device->getContext())->minorVersion()); + vector spirv = GLSL2SPIRV(stage.type, "#version 450\n" + stage.source, device->gpuDevice()->minorVersion); VkShaderModuleCreateInfo createInfo{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; createInfo.codeSize = spirv.size() * sizeof(unsigned int); createInfo.pCode = spirv.data(); diff --git a/native/cocos/renderer/gfx-vulkan/VKCommands.h b/native/cocos/renderer/gfx-vulkan/VKCommands.h index ba794f7ebc..c09833e9ba 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommands.h +++ b/native/cocos/renderer/gfx-vulkan/VKCommands.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_COMMANDS_H_ -#define CC_GFXVULKAN_COMMANDS_H_ +#pragma once #include "VKGPUObjects.h" @@ -85,5 +84,3 @@ CC_VULKAN_API void CCVKCmdFuncGlobalMemoryBarrier(const CCVKGPUCommandBuffer *gp } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKContext.cpp b/native/cocos/renderer/gfx-vulkan/VKContext.cpp index 7cfa5ed6c2..630e4d3304 100644 --- a/native/cocos/renderer/gfx-vulkan/VKContext.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKContext.cpp @@ -46,7 +46,7 @@ constexpr uint FORCE_MINOR_VERSION = 0; // 0 for default version, othe constexpr uint 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, @@ -99,18 +99,14 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debugReportCallback(VkDebugReportFlagsEXT fl #endif } // namespace -CCVKContext::CCVKContext(Device *device) -: Context(device) { +CCVKContext::CCVKContext() +: Context() { } CCVKContext::~CCVKContext() { } -bool CCVKContext::initialize(const ContextInfo &info) { - - _vsyncMode = info.vsyncMode; - _windowHandle = info.windowHandle; - +bool CCVKContext::doInit(const ContextInfo &info) { if (!info.sharedCtx) { _isPrimaryContex = true; @@ -286,9 +282,9 @@ bool CCVKContext::initialize(const ContextInfo &info) { EventDispatcher::addCustomEventListener(EVENT_DESTROY_WINDOW, [this](const CustomEvent &event) -> void { if (_gpuContext && _gpuContext->vkSurface != VK_NULL_HANDLE) { - CCVKDevice *device = (CCVKDevice *)_device; + CCVKDevice *device = CCVKDevice::getInstance(); - CCVKQueue *queue = (CCVKQueue *)_device->getQueue(); + CCVKQueue *queue = (CCVKQueue *)device->getQueue(); uint fenceCount = device->gpuFencePool()->size(); if (fenceCount) { @@ -314,7 +310,7 @@ bool CCVKContext::initialize(const ContextInfo &info) { VK_CHECK(vkCreateAndroidSurfaceKHR(_gpuContext->vkInstance, &surfaceCreateInfo, nullptr, &_gpuContext->vkSurface)); - ((CCVKDevice *)_device)->checkSwapchainStatus(); + CCVKDevice::getInstance()->checkSwapchainStatus(); } }); #elif defined(VK_USE_PLATFORM_WIN32_KHR) @@ -553,7 +549,7 @@ bool CCVKContext::initialize(const ContextInfo &info) { return true; } -void CCVKContext::destroy() { +void CCVKContext::doDestroy() { if (_gpuContext) { if (_gpuContext->vkSurface != VK_NULL_HANDLE) { vkDestroySurfaceKHR(_gpuContext->vkInstance, _gpuContext->vkSurface, nullptr); diff --git a/native/cocos/renderer/gfx-vulkan/VKContext.h b/native/cocos/renderer/gfx-vulkan/VKContext.h index f308c84510..cd41e87c26 100644 --- a/native/cocos/renderer/gfx-vulkan/VKContext.h +++ b/native/cocos/renderer/gfx-vulkan/VKContext.h @@ -39,13 +39,10 @@ class CCVKGPUSemaphorePool; class CC_VULKAN_API CCVKContext final : public Context { public: - CCVKContext(Device *device); + CCVKContext(); ~CCVKContext(); -public: - bool initialize(const ContextInfo &info); - void destroy(); - void present() {} + void present() override {} CC_INLINE bool checkExtension(const String &extension) const { return std::find_if(_extensions.begin(), _extensions.end(), @@ -60,11 +57,14 @@ public: CC_INLINE const vector &getLayers() const { return _layers; } CC_INLINE const vector &getExtensions() const { return _extensions; } -private: - CCVKGPUContext *_gpuContext = nullptr; - bool _isPrimaryContex = false; - int _majorVersion = 0; - int _minorVersion = 0; +protected: + bool doInit(const ContextInfo &info) override; + void doDestroy() override; + + CCVKGPUContext * _gpuContext = nullptr; + bool _isPrimaryContex = false; + int _majorVersion = 0; + int _minorVersion = 0; vector _layers; vector _extensions; }; diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp index daadb41ee2..05a67b410a 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp @@ -38,25 +38,18 @@ namespace cc { namespace gfx { -CCVKDescriptorSet::CCVKDescriptorSet(Device *device) -: DescriptorSet(device) { +CCVKDescriptorSet::CCVKDescriptorSet() +: DescriptorSet() { } CCVKDescriptorSet::~CCVKDescriptorSet() { } -bool CCVKDescriptorSet::initialize(const DescriptorSetInfo &info) { - - _layout = info.layout; - +void CCVKDescriptorSet::doInit(const DescriptorSetInfo &info) { CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout = ((CCVKDescriptorSetLayout *)_layout)->gpuDescriptorSetLayout(); const uint bindingCount = gpuDescriptorSetLayout->bindings.size(); const uint descriptorCount = gpuDescriptorSetLayout->descriptorCount; - _buffers.resize(descriptorCount); - _textures.resize(descriptorCount); - _samplers.resize(descriptorCount); - _gpuDescriptorSet = CC_NEW(CCVKGPUDescriptorSet); _gpuDescriptorSet->gpuDescriptors.resize(descriptorCount, {}); @@ -96,7 +89,7 @@ bool CCVKDescriptorSet::initialize(const DescriptorSetInfo &info) { } } - CCVKGPUDevice *gpuDevice = ((CCVKDevice *)_device)->gpuDevice(); + CCVKGPUDevice *gpuDevice = CCVKDevice::getInstance()->gpuDevice(); _gpuDescriptorSet->gpuLayout = gpuDescriptorSetLayout; _gpuDescriptorSet->instances.resize(gpuDevice->backBufferCount); @@ -158,13 +151,11 @@ bool CCVKDescriptorSet::initialize(const DescriptorSetInfo &info) { } } } - - return true; } -void CCVKDescriptorSet::destroy() { +void CCVKDescriptorSet::doDestroy() { if (_gpuDescriptorSet) { - CCVKGPUDescriptorHub * descriptorHub = ((CCVKDevice *)_device)->gpuDescriptorHub(); + CCVKGPUDescriptorHub * descriptorHub = CCVKDevice::getInstance()->gpuDescriptorHub(); CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout = ((CCVKDescriptorSetLayout *)_layout)->gpuDescriptorSetLayout(); for (size_t t = 0u; t < _gpuDescriptorSet->instances.size(); ++t) { @@ -190,22 +181,17 @@ void CCVKDescriptorSet::destroy() { } } - ((CCVKDevice *)_device)->gpuDescriptorSetHub()->erase(_gpuDescriptorSet); + CCVKDevice::getInstance()->gpuDescriptorSetHub()->erase(_gpuDescriptorSet); CC_DELETE(_gpuDescriptorSet); _gpuDescriptorSet = nullptr; } - - // do remember to clear these or else it might not be properly updated when reused - _buffers.clear(); - _textures.clear(); - _samplers.clear(); } void CCVKDescriptorSet::update() { if (_isDirty && _gpuDescriptorSet) { - CCVKGPUDescriptorHub * descriptorHub = ((CCVKDevice *)_device)->gpuDescriptorHub(); - CCVKGPUBarrierManager *layoutMgr = ((CCVKDevice *)_device)->gpuBarrierManager(); + CCVKGPUDescriptorHub * descriptorHub = CCVKDevice::getInstance()->gpuDescriptorHub(); + CCVKGPUBarrierManager *layoutMgr = CCVKDevice::getInstance()->gpuBarrierManager(); uint descriptorCount = _gpuDescriptorSet->gpuDescriptors.size(); for (size_t i = 0u; i < descriptorCount; i++) { @@ -266,7 +252,7 @@ void CCVKDescriptorSet::update() { } } } - ((CCVKDevice *)_device)->gpuDescriptorSetHub()->record(_gpuDescriptorSet); + CCVKDevice::getInstance()->gpuDescriptorSetHub()->record(_gpuDescriptorSet); _isDirty = false; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.h b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.h index da4ae3c09a..fb4cbbd506 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.h +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_BINDING_LAYOUT_H_ -#define CC_GFXVULKAN_BINDING_LAYOUT_H_ +#pragma once #include "gfx-base/GFXDescriptorSet.h" @@ -35,20 +34,19 @@ class CCVKGPUDescriptorSet; class CC_VULKAN_API CCVKDescriptorSet final : public DescriptorSet { public: - CCVKDescriptorSet(Device *device); + CCVKDescriptorSet(); ~CCVKDescriptorSet(); - virtual bool initialize(const DescriptorSetInfo &info) override; - virtual void destroy() override; - virtual void update() override; + void update() override; CC_INLINE CCVKGPUDescriptorSet *gpuDescriptorSet() const { return _gpuDescriptorSet; } -private: +protected: + void doInit(const DescriptorSetInfo &info) override; + void doDestroy() override; + CCVKGPUDescriptorSet *_gpuDescriptorSet = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp b/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp index 58f7da331b..4e0baa85a6 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.cpp @@ -32,45 +32,21 @@ namespace cc { namespace gfx { -CCVKDescriptorSetLayout::CCVKDescriptorSetLayout(Device *device) -: DescriptorSetLayout(device) { +CCVKDescriptorSetLayout::CCVKDescriptorSetLayout() +: DescriptorSetLayout() { } CCVKDescriptorSetLayout::~CCVKDescriptorSetLayout() { } -bool CCVKDescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { - - _bindings = info.bindings; - uint bindingCount = _bindings.size(); - _descriptorCount = 0u; - - if (bindingCount) { - uint maxBinding = 0u; - vector flattenedIndices(bindingCount); - for (uint i = 0u; i < bindingCount; i++) { - const DescriptorSetLayoutBinding &binding = _bindings[i]; - flattenedIndices[i] = _descriptorCount; - _descriptorCount += binding.count; - if (binding.binding > maxBinding) maxBinding = binding.binding; - } - - _bindingIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); - _descriptorIndices.resize(maxBinding + 1, GFX_INVALID_BINDING); - for (uint i = 0u; i < bindingCount; i++) { - const DescriptorSetLayoutBinding &binding = _bindings[i]; - _bindingIndices[binding.binding] = i; - _descriptorIndices[binding.binding] = flattenedIndices[i]; - } - } - +void CCVKDescriptorSetLayout::doInit(const DescriptorSetLayoutInfo &info) { _gpuDescriptorSetLayout = CC_NEW(CCVKGPUDescriptorSetLayout); _gpuDescriptorSetLayout->descriptorCount = _descriptorCount; _gpuDescriptorSetLayout->bindingIndices = _bindingIndices; _gpuDescriptorSetLayout->descriptorIndices = _descriptorIndices; _gpuDescriptorSetLayout->bindings = _bindings; - for (uint i = 0u; i < bindingCount; i++) { + for (uint i = 0u; i < _bindings.size(); i++) { const DescriptorSetLayoutBinding &binding = _bindings[i]; if (binding.descriptorType & DESCRIPTOR_DYNAMIC_TYPE) { for (uint j = 0u; j < binding.count; j++) { @@ -79,14 +55,12 @@ bool CCVKDescriptorSetLayout::initialize(const DescriptorSetLayoutInfo &info) { } } - CCVKCmdFuncCreateDescriptorSetLayout((CCVKDevice *)_device, _gpuDescriptorSetLayout); - - return true; + CCVKCmdFuncCreateDescriptorSetLayout(CCVKDevice::getInstance(), _gpuDescriptorSetLayout); } -void CCVKDescriptorSetLayout::destroy() { +void CCVKDescriptorSetLayout::doDestroy() { if (_gpuDescriptorSetLayout) { - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuDescriptorSetLayout); + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuDescriptorSetLayout); _gpuDescriptorSetLayout = nullptr; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.h b/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.h index ee88a47ae2..d979492b45 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.h +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSetLayout.h @@ -35,16 +35,15 @@ class CCVKGPUDescriptorSetLayout; class CC_VULKAN_API CCVKDescriptorSetLayout final : public DescriptorSetLayout { public: - CCVKDescriptorSetLayout(Device *device); + CCVKDescriptorSetLayout(); ~CCVKDescriptorSetLayout(); -public: - virtual bool initialize(const DescriptorSetLayoutInfo &info) override; - virtual void destroy() override; - CC_INLINE CCVKGPUDescriptorSetLayout *gpuDescriptorSetLayout() const { return _gpuDescriptorSetLayout; } -private: +protected: + void doInit(const DescriptorSetLayoutInfo &info) override; + void doDestroy() override; + CCVKGPUDescriptorSetLayout *_gpuDescriptorSetLayout = nullptr; }; diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp index 8bc5d074e5..feb8d81e72 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.cpp @@ -59,45 +59,40 @@ namespace gfx { //#define DISABLE_PRE_TRANSFORM +CCVKDevice *CCVKDevice::_instance = nullptr; + +CCVKDevice *CCVKDevice::getInstance() { + return CCVKDevice::_instance; +} + CCVKDevice::CCVKDevice() { + _API = API::VULKAN; + _deviceName = "Vulkan"; + _caps.clipSpaceMinZ = 0.0f; _caps.screenSpaceSignY = -1.0f; _caps.UVSpaceSignY = 1.0f; + CCVKDevice::_instance = this; } CCVKDevice::~CCVKDevice() { + CCVKDevice::_instance = nullptr; } CCVKGPUContext *CCVKDevice::gpuContext() const { return ((CCVKContext *)_context)->gpuContext(); } -bool CCVKDevice::initialize(const DeviceInfo &info) { - _API = API::VULKAN; - _deviceName = "Vulkan"; - _width = info.width; - _height = info.height; - _nativeWidth = info.nativeWidth; - _nativeHeight = info.nativeHeight; - _windowHandle = info.windowHandle; +bool CCVKDevice::doInit(const DeviceInfo &info) { + ContextInfo ctxInfo; + ctxInfo.windowHandle = _windowHandle; - _bindingMappingInfo = info.bindingMappingInfo; - if (!_bindingMappingInfo.bufferOffsets.size()) { - _bindingMappingInfo.bufferOffsets.push_back(0); - } - if (!_bindingMappingInfo.samplerOffsets.size()) { - _bindingMappingInfo.samplerOffsets.push_back(0); - } - - ContextInfo contextCreateInfo; - contextCreateInfo.windowHandle = _windowHandle; - contextCreateInfo.sharedCtx = info.sharedCtx; - - _context = CC_NEW(CCVKContext(this)); - if (!_context->initialize(contextCreateInfo)) { + _context = CC_NEW(CCVKContext); + if (!_context->initialize(ctxInfo)) { destroy(); return false; } + const CCVKContext * context = (CCVKContext *)_context; const CCVKGPUContext * gpuContext = ((CCVKContext *)_context)->gpuContext(); const VkPhysicalDeviceFeatures2 &deviceFeatures2 = gpuContext->physicalDeviceFeatures2; @@ -297,6 +292,15 @@ bool CCVKDevice::initialize(const DeviceInfo &info) { ///////////////////// Resource Initialization ///////////////////// + QueueInfo queueInfo; + queueInfo.type = QueueType::GRAPHICS; + _queue = createQueue(queueInfo); + + CommandBufferInfo cmdBuffInfo; + cmdBuffInfo.type = CommandBufferType::PRIMARY; + cmdBuffInfo.queue = _queue; + _cmdBuff = createCommandBuffer(cmdBuffInfo); + VmaVulkanFunctions vmaVulkanFunc{}; vmaVulkanFunc.vkAllocateMemory = vkAllocateMemory; vmaVulkanFunc.vkBindBufferMemory = vkBindBufferMemory; @@ -335,10 +339,6 @@ bool CCVKDevice::initialize(const DeviceInfo &info) { VK_CHECK(vmaCreateAllocator(&allocatorInfo, &_gpuDevice->memoryAllocator)); - QueueInfo queueInfo; - queueInfo.type = QueueType::GRAPHICS; - _queue = createQueue(queueInfo); - uint backBufferCount = gpuContext->swapchainCreateInfo.minImageCount; for (uint i = 0u; i < backBufferCount; i++) { _gpuFencePools.push_back(CC_NEW(CCVKGPUFencePool(_gpuDevice))); @@ -355,11 +355,6 @@ bool CCVKDevice::initialize(const DeviceInfo &info) { _gpuDescriptorHub->link(_gpuDescriptorSetHub); - CommandBufferInfo cmdBuffInfo; - cmdBuffInfo.type = CommandBufferType::PRIMARY; - cmdBuffInfo.queue = _queue; - _cmdBuff = createCommandBuffer(cmdBuffInfo); - CCVKCmdFuncCreateSampler(this, &_gpuDevice->defaultSampler); _gpuDevice->defaultTexture.format = Format::RGBA8; @@ -448,7 +443,7 @@ bool CCVKDevice::initialize(const DeviceInfo &info) { return true; } -void CCVKDevice::destroy() { +void CCVKDevice::doDestroy() { if (_gpuDevice && _gpuDevice->vkDevice) { VK_CHECK(vkDeviceWaitIdle(_gpuDevice->vkDevice)); } @@ -557,9 +552,9 @@ void CCVKDevice::acquire() { VK_CHECK(vkAcquireNextImageKHR(_gpuDevice->vkDevice, _gpuSwapchain->vkSwapchain, ~0ull, acquireSemaphore, VK_NULL_HANDLE, &_gpuSwapchain->curImageIndex)); -#if defined(VK_USE_PLATFORM_METAL_EXT) +#if !defined(VK_USE_PLATFORM_METAL_EXT) assert(_gpuDevice->curBackBufferIndex == _gpuSwapchain->curImageIndex); // MoltenVK seems to be not consistent -#endif // defined(VK_USE_PLATFORM_METAL_EXT) +#endif // defined(VK_USE_PLATFORM_METAL_EXT) queue->gpuQueue()->nextWaitSemaphore = acquireSemaphore; queue->gpuQueue()->nextSignalSemaphore = _gpuSemaphorePool->alloc(); @@ -602,64 +597,64 @@ CCVKGPUFencePool * CCVKDevice::gpuFencePool() { return _gpuFencePools[_gp CCVKGPURecycleBin * CCVKDevice::gpuRecycleBin() { return _gpuRecycleBins[_gpuDevice->curBackBufferIndex]; } CCVKGPUStagingBufferPool *CCVKDevice::gpuStagingBufferPool() { return _gpuStagingBufferPools[_gpuDevice->curBackBufferIndex]; } -CommandBuffer *CCVKDevice::doCreateCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { - return CC_NEW(CCVKCommandBuffer(this)); +CommandBuffer *CCVKDevice::createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) { + return CC_NEW(CCVKCommandBuffer); } Queue *CCVKDevice::createQueue() { - return CC_NEW(CCVKQueue(this)); + return CC_NEW(CCVKQueue); } Buffer *CCVKDevice::createBuffer() { - return CC_NEW(CCVKBuffer(this)); + return CC_NEW(CCVKBuffer); } Texture *CCVKDevice::createTexture() { - return CC_NEW(CCVKTexture(this)); + return CC_NEW(CCVKTexture); } Sampler *CCVKDevice::createSampler() { - return CC_NEW(CCVKSampler(this)); + return CC_NEW(CCVKSampler); } Shader *CCVKDevice::createShader() { - return CC_NEW(CCVKShader(this)); + return CC_NEW(CCVKShader); } InputAssembler *CCVKDevice::createInputAssembler() { - return CC_NEW(CCVKInputAssembler(this)); + return CC_NEW(CCVKInputAssembler); } RenderPass *CCVKDevice::createRenderPass() { - return CC_NEW(CCVKRenderPass(this)); + return CC_NEW(CCVKRenderPass); } Framebuffer *CCVKDevice::createFramebuffer() { - return CC_NEW(CCVKFramebuffer(this)); + return CC_NEW(CCVKFramebuffer); } DescriptorSet *CCVKDevice::createDescriptorSet() { - return CC_NEW(CCVKDescriptorSet(this)); + return CC_NEW(CCVKDescriptorSet); } DescriptorSetLayout *CCVKDevice::createDescriptorSetLayout() { - return CC_NEW(CCVKDescriptorSetLayout(this)); + return CC_NEW(CCVKDescriptorSetLayout); } PipelineLayout *CCVKDevice::createPipelineLayout() { - return CC_NEW(CCVKPipelineLayout(this)); + return CC_NEW(CCVKPipelineLayout); } PipelineState *CCVKDevice::createPipelineState() { - return CC_NEW(CCVKPipelineState(this)); + return CC_NEW(CCVKPipelineState); } GlobalBarrier *CCVKDevice::createGlobalBarrier() { - return CC_NEW(CCVKGlobalBarrier(this)); + return CC_NEW(CCVKGlobalBarrier); } TextureBarrier *CCVKDevice::createTextureBarrier() { - return CC_NEW(CCVKTextureBarrier(this)); + return CC_NEW(CCVKTextureBarrier); } void CCVKDevice::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) { diff --git a/native/cocos/renderer/gfx-vulkan/VKDevice.h b/native/cocos/renderer/gfx-vulkan/VKDevice.h index ad6c2e0f0b..82a9ff9f3c 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDevice.h +++ b/native/cocos/renderer/gfx-vulkan/VKDevice.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_DEVICE_H_ -#define CC_GFXVULKAN_DEVICE_H_ +#pragma once #include "gfx-base/GFXDevice.h" @@ -50,8 +49,9 @@ class CCVKGPUStagingBufferPool; class CC_VULKAN_API CCVKDevice final : public Device { public: - CCVKDevice(); - ~CCVKDevice(); + static CCVKDevice *getInstance(); + + ~CCVKDevice() override; friend class CCVKContext; using Device::copyBuffersToTexture; @@ -71,11 +71,10 @@ public: using Device::createTexture; using Device::createTextureBarrier; - virtual bool initialize(const DeviceInfo &info) override; - virtual void destroy() override; - virtual void resize(uint width, uint height) override; - virtual void acquire() override; - virtual void present() override; + void resize(uint width, uint height) override; + void acquire() override; + void present() override; + CC_INLINE bool checkExtension(const String &extension) const { return std::find_if(_extensions.begin(), _extensions.end(), [extension](const char *device_extension) { @@ -98,23 +97,31 @@ public: CCVKGPURecycleBin * gpuRecycleBin(); CCVKGPUStagingBufferPool *gpuStagingBufferPool(); -private: - virtual CommandBuffer * doCreateCommandBuffer(const CommandBufferInfo &info, bool hasAgent) override; - virtual Queue * createQueue() override; - virtual Buffer * createBuffer() override; - virtual Texture * createTexture() override; - virtual Sampler * createSampler() override; - virtual Shader * createShader() override; - virtual InputAssembler * createInputAssembler() override; - virtual RenderPass * createRenderPass() override; - virtual Framebuffer * createFramebuffer() override; - virtual DescriptorSet * createDescriptorSet() override; - virtual DescriptorSetLayout *createDescriptorSetLayout() override; - virtual PipelineLayout * createPipelineLayout() override; - virtual PipelineState * createPipelineState() override; - virtual GlobalBarrier * createGlobalBarrier() override; - virtual TextureBarrier * createTextureBarrier() override; - virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; +protected: + static CCVKDevice *_instance; + + friend class DeviceCreator; + + CCVKDevice(); + + bool doInit(const DeviceInfo &info) override; + void doDestroy() override; + CommandBuffer * createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) override; + Queue * createQueue() override; + Buffer * createBuffer() override; + Texture * createTexture() override; + Sampler * createSampler() override; + Shader * createShader() override; + InputAssembler * createInputAssembler() override; + RenderPass * createRenderPass() override; + Framebuffer * createFramebuffer() override; + DescriptorSet * createDescriptorSet() override; + DescriptorSetLayout *createDescriptorSetLayout() override; + PipelineLayout * createPipelineLayout() override; + PipelineState * createPipelineState() override; + GlobalBarrier * createGlobalBarrier() override; + TextureBarrier * createTextureBarrier() override; + void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override; void destroySwapchain(); bool checkSwapchainStatus(); @@ -142,5 +149,3 @@ private: } // namespace gfx } // namespace cc - -#endif // CC_GFXVULKAN_DEVICE_H_ diff --git a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp index b272a8bc40..20b509db40 100644 --- a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.cpp @@ -34,18 +34,14 @@ namespace cc { namespace gfx { -CCVKFramebuffer::CCVKFramebuffer(Device *device) -: Framebuffer(device) { +CCVKFramebuffer::CCVKFramebuffer() +: Framebuffer() { } CCVKFramebuffer::~CCVKFramebuffer() { } -bool CCVKFramebuffer::initialize(const FramebufferInfo &info) { - _renderPass = info.renderPass; - _colorTextures = info.colorTextures; - _depthStencilTexture = info.depthStencilTexture; - +void CCVKFramebuffer::doInit(const FramebufferInfo &info) { _gpuFBO = CC_NEW(CCVKGPUFramebuffer); _gpuFBO->gpuRenderPass = ((CCVKRenderPass *)_renderPass)->gpuRenderPass(); @@ -61,14 +57,12 @@ bool CCVKFramebuffer::initialize(const FramebufferInfo &info) { _gpuFBO->gpuDepthStencilView = ((CCVKTexture *)_depthStencilTexture)->gpuTextureView(); } - CCVKCmdFuncCreateFramebuffer((CCVKDevice *)_device, _gpuFBO); - - return true; + CCVKCmdFuncCreateFramebuffer(CCVKDevice::getInstance(), _gpuFBO); } -void CCVKFramebuffer::destroy() { +void CCVKFramebuffer::doDestroy() { if (_gpuFBO) { - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuFBO); + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuFBO); _gpuFBO = nullptr; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.h b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.h index 6bc1b92a17..8dca815263 100644 --- a/native/cocos/renderer/gfx-vulkan/VKFramebuffer.h +++ b/native/cocos/renderer/gfx-vulkan/VKFramebuffer.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_FRAMEBUFFER_H_ -#define CC_GFXVULKAN_FRAMEBUFFER_H_ +#pragma once #include "gfx-base/GFXFramebuffer.h" @@ -35,20 +34,17 @@ class CCVKGPUFramebuffer; class CC_VULKAN_API CCVKFramebuffer final : public Framebuffer { public: - CCVKFramebuffer(Device *device); + CCVKFramebuffer(); ~CCVKFramebuffer() override; -public: - bool initialize(const FramebufferInfo &info); - void destroy(); - CC_INLINE CCVKGPUFramebuffer *gpuFBO() const { return _gpuFBO; } -private: +protected: + void doInit(const FramebufferInfo &info) override; + void doDestroy() override; + CCVKGPUFramebuffer *_gpuFBO = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h index 11b753f61c..bd03728257 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h +++ b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_GPU_OBJECTS_H_ -#define CC_GFXVULKAN_GPU_OBJECTS_H_ +#pragma once #include "VKUtils.h" @@ -1243,5 +1242,3 @@ private: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKGlobalBarrier.cpp b/native/cocos/renderer/gfx-vulkan/VKGlobalBarrier.cpp index 44b1e44a42..122fd275c5 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGlobalBarrier.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKGlobalBarrier.cpp @@ -31,17 +31,15 @@ namespace cc { namespace gfx { -CCVKGlobalBarrier::CCVKGlobalBarrier(Device *device) -: GlobalBarrier(device) { +CCVKGlobalBarrier::CCVKGlobalBarrier() +: GlobalBarrier() { } CCVKGlobalBarrier::~CCVKGlobalBarrier() { CC_SAFE_DELETE(_gpuBarrier); } -bool CCVKGlobalBarrier::initialize(const GlobalBarrierInfo &info) { - _info = info; - +void CCVKGlobalBarrier::doInit(const GlobalBarrierInfo &info) { _gpuBarrier = CC_NEW(CCVKGPUGlobalBarrier); _gpuBarrier->accessTypes.resize(info.prevAccesses.size() + info.nextAccesses.size()); @@ -59,8 +57,6 @@ bool CCVKGlobalBarrier::initialize(const GlobalBarrierInfo &info) { _gpuBarrier->barrier.pNextAccesses = _gpuBarrier->accessTypes.data() + info.prevAccesses.size(); thsvsGetVulkanMemoryBarrier(_gpuBarrier->barrier, &_gpuBarrier->srcStageMask, &_gpuBarrier->dstStageMask, &_gpuBarrier->vkBarrier); - - return true; } } // namespace gfx diff --git a/native/cocos/renderer/gfx-vulkan/VKGlobalBarrier.h b/native/cocos/renderer/gfx-vulkan/VKGlobalBarrier.h index 7c721a61b4..ee9cf2ecc3 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGlobalBarrier.h +++ b/native/cocos/renderer/gfx-vulkan/VKGlobalBarrier.h @@ -35,13 +35,13 @@ class CCVKGPUGlobalBarrier; class CC_DLL CCVKGlobalBarrier : public GlobalBarrier { public: - CCVKGlobalBarrier(Device *device); + CCVKGlobalBarrier(); ~CCVKGlobalBarrier(); CC_INLINE const CCVKGPUGlobalBarrier *gpuBarrier() const { return _gpuBarrier; } protected: - bool initialize(const GlobalBarrierInfo &info) override; + void doInit(const GlobalBarrierInfo &info) override; CCVKGPUGlobalBarrier *_gpuBarrier = nullptr; }; diff --git a/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cpp b/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cpp index 7fbf2f50fb..c728a2746c 100644 --- a/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKInputAssembler.cpp @@ -33,29 +33,16 @@ namespace cc { namespace gfx { -CCVKInputAssembler::CCVKInputAssembler(Device *device) -: InputAssembler(device) { +CCVKInputAssembler::CCVKInputAssembler() +: InputAssembler() { } CCVKInputAssembler::~CCVKInputAssembler() { } -bool CCVKInputAssembler::initialize(const InputAssemblerInfo &info) { - _attributes = info.attributes; - _vertexBuffers = info.vertexBuffers; - _indexBuffer = info.indexBuffer; - _indirectBuffer = info.indirectBuffer; +void CCVKInputAssembler::doInit(const InputAssemblerInfo &info) { size_t vbCount = _vertexBuffers.size(); - if (_indexBuffer) { - _indexCount = _indexBuffer->getCount(); - _firstIndex = 0; - } else if (_vertexBuffers.size()) { - _vertexCount = _vertexBuffers[0]->getCount(); - _firstVertex = 0; - _vertexOffset = 0; - } - _gpuInputAssembler = CC_NEW(CCVKGPUInputAssembler); _gpuInputAssembler->attributes = _attributes; _gpuInputAssembler->gpuVertexBuffers.resize(vbCount); @@ -80,13 +67,9 @@ bool CCVKInputAssembler::initialize(const InputAssemblerInfo &info) { _gpuInputAssembler->vertexBuffers[i] = _gpuInputAssembler->gpuVertexBuffers[i]->vkBuffer; _gpuInputAssembler->vertexBufferOffsets[i] = _gpuInputAssembler->gpuVertexBuffers[i]->startOffset; } - - _attributesHash = computeAttributesHash(); - - return true; } -void CCVKInputAssembler::destroy() { +void CCVKInputAssembler::doDestroy() { if (_gpuInputAssembler) { _gpuInputAssembler->vertexBuffers.clear(); _gpuInputAssembler->vertexBufferOffsets.clear(); diff --git a/native/cocos/renderer/gfx-vulkan/VKInputAssembler.h b/native/cocos/renderer/gfx-vulkan/VKInputAssembler.h index 2b6230f331..ddb2498516 100644 --- a/native/cocos/renderer/gfx-vulkan/VKInputAssembler.h +++ b/native/cocos/renderer/gfx-vulkan/VKInputAssembler.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_INPUT_ASSEMBLER_H_ -#define CC_GFXVULKAN_INPUT_ASSEMBLER_H_ +#pragma once #include "gfx-base/GFXInputAssembler.h" @@ -35,20 +34,17 @@ class CCVKGPUInputAssembler; class CC_VULKAN_API CCVKInputAssembler final : public InputAssembler { public: - CCVKInputAssembler(Device *device); + CCVKInputAssembler(); ~CCVKInputAssembler(); -public: - bool initialize(const InputAssemblerInfo &info); - void destroy(); - CC_INLINE CCVKGPUInputAssembler *gpuInputAssembler() const { return _gpuInputAssembler; } -private: +protected: + void doInit(const InputAssemblerInfo &info) override; + void doDestroy() override; + CCVKGPUInputAssembler *_gpuInputAssembler = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.cpp b/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.cpp index b96af66907..71bfc1c632 100644 --- a/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.cpp @@ -33,17 +33,14 @@ namespace cc { namespace gfx { -CCVKPipelineLayout::CCVKPipelineLayout(Device *device) -: PipelineLayout(device) { +CCVKPipelineLayout::CCVKPipelineLayout() +: PipelineLayout() { } CCVKPipelineLayout::~CCVKPipelineLayout() { } -bool CCVKPipelineLayout::initialize(const PipelineLayoutInfo &info) { - - _setLayouts = info.setLayouts; - +void CCVKPipelineLayout::doInit(const PipelineLayoutInfo &info) { _gpuPipelineLayout = CC_NEW(CCVKGPUPipelineLayout); int offset = 0u; @@ -59,15 +56,12 @@ bool CCVKPipelineLayout::initialize(const PipelineLayoutInfo &info) { _gpuPipelineLayout->dynamicOffsetOffsets.push_back(offset); _gpuPipelineLayout->dynamicOffsetCount = offset; - CCVKCmdFuncCreatePipelineLayout((CCVKDevice *)_device, _gpuPipelineLayout); - - return true; + CCVKCmdFuncCreatePipelineLayout(CCVKDevice::getInstance(), _gpuPipelineLayout); } -void CCVKPipelineLayout::destroy() { - +void CCVKPipelineLayout::doDestroy() { if (_gpuPipelineLayout) { - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuPipelineLayout); + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuPipelineLayout); _gpuPipelineLayout = nullptr; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.h b/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.h index c9578f3a7c..2162d8e7a5 100644 --- a/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.h +++ b/native/cocos/renderer/gfx-vulkan/VKPipelineLayout.h @@ -35,16 +35,15 @@ class CCVKGPUPipelineLayout; class CC_VULKAN_API CCVKPipelineLayout final : public PipelineLayout { public: - CCVKPipelineLayout(Device *device); + CCVKPipelineLayout(); ~CCVKPipelineLayout(); -public: - virtual bool initialize(const PipelineLayoutInfo &info) override; - virtual void destroy() override; - CC_INLINE CCVKGPUPipelineLayout *gpuPipelineLayout() const { return _gpuPipelineLayout; } -private: +protected: + void doInit(const PipelineLayoutInfo &info) override; + void doDestroy() override; + CCVKGPUPipelineLayout *_gpuPipelineLayout = nullptr; }; diff --git a/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp b/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp index 25802d90be..de875ff53f 100644 --- a/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKPipelineState.cpp @@ -35,25 +35,14 @@ namespace cc { namespace gfx { -CCVKPipelineState::CCVKPipelineState(Device *device) -: PipelineState(device) { +CCVKPipelineState::CCVKPipelineState() +: PipelineState() { } CCVKPipelineState::~CCVKPipelineState() { } -bool CCVKPipelineState::initialize(const PipelineStateInfo &info) { - _primitive = info.primitive; - _shader = info.shader; - _inputState = info.inputState; - _rasterizerState = info.rasterizerState; - _depthStencilState = info.depthStencilState; - _bindPoint = info.bindPoint; - _blendState = info.blendState; - _dynamicStates = info.dynamicStates; - _renderPass = info.renderPass; - _pipelineLayout = info.pipelineLayout; - +void CCVKPipelineState::doInit(const PipelineStateInfo &info) { _gpuPipelineState = CC_NEW(CCVKGPUPipelineState); _gpuPipelineState->bindPoint = _bindPoint; _gpuPipelineState->primitive = _primitive; @@ -72,17 +61,15 @@ bool CCVKPipelineState::initialize(const PipelineStateInfo &info) { } if (_bindPoint == PipelineBindPoint::GRAPHICS) { - CCVKCmdFuncCreateGraphicsPipelineState((CCVKDevice *)_device, _gpuPipelineState); + CCVKCmdFuncCreateGraphicsPipelineState(CCVKDevice::getInstance(), _gpuPipelineState); } else { - CCVKCmdFuncCreateComputePipelineState((CCVKDevice *)_device, _gpuPipelineState); + CCVKCmdFuncCreateComputePipelineState(CCVKDevice::getInstance(), _gpuPipelineState); } - - return true; } -void CCVKPipelineState::destroy() { +void CCVKPipelineState::doDestroy() { if (_gpuPipelineState) { - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuPipelineState); + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuPipelineState); _gpuPipelineState = nullptr; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKPipelineState.h b/native/cocos/renderer/gfx-vulkan/VKPipelineState.h index bdc4acfdd1..9b5a8529c4 100644 --- a/native/cocos/renderer/gfx-vulkan/VKPipelineState.h +++ b/native/cocos/renderer/gfx-vulkan/VKPipelineState.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_PIPELINE_STATE_H_ -#define CC_GFXVULKAN_PIPELINE_STATE_H_ +#pragma once #include "gfx-base/GFXPipelineState.h" @@ -35,20 +34,17 @@ class CCVKGPUPipelineState; class CC_VULKAN_API CCVKPipelineState final : public PipelineState { public: - CCVKPipelineState(Device *device); + CCVKPipelineState(); ~CCVKPipelineState(); -public: - bool initialize(const PipelineStateInfo &info); - void destroy(); - CC_INLINE CCVKGPUPipelineState *gpuPipelineState() const { return _gpuPipelineState; } -private: +protected: + void doInit(const PipelineStateInfo &info) override; + void doDestroy() override; + CCVKGPUPipelineState *_gpuPipelineState = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKQueue.cpp b/native/cocos/renderer/gfx-vulkan/VKQueue.cpp index 084ddbd3fc..2cd172584b 100644 --- a/native/cocos/renderer/gfx-vulkan/VKQueue.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKQueue.cpp @@ -33,24 +33,20 @@ namespace cc { namespace gfx { -CCVKQueue::CCVKQueue(Device *device) -: Queue(device) { +CCVKQueue::CCVKQueue() +: Queue() { } CCVKQueue::~CCVKQueue() { } -bool CCVKQueue::initialize(const QueueInfo &info) { - _type = info.type; - +void CCVKQueue::doInit(const QueueInfo &info) { _gpuQueue = CC_NEW(CCVKGPUQueue); _gpuQueue->type = _type; - CCVKCmdFuncGetDeviceQueue((CCVKDevice *)_device, _gpuQueue); - - return true; + CCVKCmdFuncGetDeviceQueue(CCVKDevice::getInstance(), _gpuQueue); } -void CCVKQueue::destroy() { +void CCVKQueue::doDestroy() { if (_gpuQueue) { _gpuQueue->vkQueue = VK_NULL_HANDLE; CC_DELETE(_gpuQueue); @@ -59,7 +55,7 @@ void CCVKQueue::destroy() { } void CCVKQueue::submit(CommandBuffer *const *cmdBuffs, uint count) { - CCVKDevice *device = (CCVKDevice *)_device; + CCVKDevice *device = CCVKDevice::getInstance(); _gpuQueue->commandBuffers.clear(); #if BARRIER_DEDUCTION_LEVEL >= BARRIER_DEDUCTION_LEVEL_BASIC diff --git a/native/cocos/renderer/gfx-vulkan/VKQueue.h b/native/cocos/renderer/gfx-vulkan/VKQueue.h index 227af9e50f..0bbb364a79 100644 --- a/native/cocos/renderer/gfx-vulkan/VKQueue.h +++ b/native/cocos/renderer/gfx-vulkan/VKQueue.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_QUEUE_H_ -#define CC_GFXVULKAN_QUEUE_H_ +#pragma once #include "gfx-base/GFXQueue.h" @@ -35,18 +34,19 @@ class CCVKGPUQueue; class CC_VULKAN_API CCVKQueue final : public Queue { public: - CCVKQueue(Device *device); + CCVKQueue(); ~CCVKQueue(); - friend class CCVKDevice; - - bool initialize(const QueueInfo &info); - void destroy(); - void submit(CommandBuffer *const *cmdBuffs, uint count); + void submit(CommandBuffer *const *cmdBuffs, uint count) override; CC_INLINE CCVKGPUQueue *gpuQueue() const { return _gpuQueue; } -private: +protected: + friend class CCVKDevice; + + void doInit(const QueueInfo &info) override; + void doDestroy() override; + CCVKGPUQueue *_gpuQueue = nullptr; uint _numDrawCalls = 0; @@ -56,5 +56,3 @@ private: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp b/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp index 96b8777d12..f173c66265 100644 --- a/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKRenderPass.cpp @@ -32,32 +32,24 @@ namespace cc { namespace gfx { -CCVKRenderPass::CCVKRenderPass(Device *device) -: RenderPass(device) { +CCVKRenderPass::CCVKRenderPass() +: RenderPass() { } CCVKRenderPass::~CCVKRenderPass() { } -bool CCVKRenderPass::initialize(const RenderPassInfo &info) { - _colorAttachments = info.colorAttachments; - _depthStencilAttachment = info.depthStencilAttachment; - _subpasses = info.subpasses; - +void CCVKRenderPass::doInit(const RenderPassInfo &info) { _gpuRenderPass = CC_NEW(CCVKGPURenderPass); _gpuRenderPass->colorAttachments = _colorAttachments; _gpuRenderPass->depthStencilAttachment = _depthStencilAttachment; _gpuRenderPass->subpasses = _subpasses; - CCVKCmdFuncCreateRenderPass((CCVKDevice *)_device, _gpuRenderPass); - - _hash = computeHash(); - - return true; + CCVKCmdFuncCreateRenderPass(CCVKDevice::getInstance(), _gpuRenderPass); } -void CCVKRenderPass::destroy() { +void CCVKRenderPass::doDestroy() { if (_gpuRenderPass) { - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuRenderPass); + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuRenderPass); _gpuRenderPass = nullptr; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKRenderPass.h b/native/cocos/renderer/gfx-vulkan/VKRenderPass.h index bc95cdfe7c..1574c5384b 100644 --- a/native/cocos/renderer/gfx-vulkan/VKRenderPass.h +++ b/native/cocos/renderer/gfx-vulkan/VKRenderPass.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_RENDER_PASS_H_ -#define CC_GFXVULKAN_RENDER_PASS_H_ +#pragma once #include "gfx-base/GFXRenderPass.h" @@ -35,20 +34,17 @@ class CCVKGPURenderPass; class CC_VULKAN_API CCVKRenderPass final : public RenderPass { public: - CCVKRenderPass(Device *device); + CCVKRenderPass(); ~CCVKRenderPass(); -public: - bool initialize(const RenderPassInfo &info); - void destroy(); - CC_INLINE CCVKGPURenderPass *gpuRenderPass() const { return _gpuRenderPass; } -private: +protected: + void doInit(const RenderPassInfo &info) override; + void doDestroy() override; + CCVKGPURenderPass *_gpuRenderPass = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKSPIRV.h b/native/cocos/renderer/gfx-vulkan/VKSPIRV.h index 44a04c4cce..923a4a777a 100644 --- a/native/cocos/renderer/gfx-vulkan/VKSPIRV.h +++ b/native/cocos/renderer/gfx-vulkan/VKSPIRV.h @@ -23,10 +23,9 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_SPIRV_H_ -#define CC_GFXVULKAN_SPIRV_H_ +#pragma once -#include "SPIRV/GlslangToSpv.h" +#include "glslang/SPIRV/GlslangToSpv.h" #include "glslang/Public/ShaderLang.h" #include "StandAlone/ResourceLimits.h" @@ -119,5 +118,3 @@ const vector GLSL2SPIRV(ShaderStageFlagBit type, const String &sou } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKSampler.cpp b/native/cocos/renderer/gfx-vulkan/VKSampler.cpp index cf887131ef..04bdff58e7 100644 --- a/native/cocos/renderer/gfx-vulkan/VKSampler.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKSampler.cpp @@ -32,25 +32,14 @@ namespace cc { namespace gfx { -CCVKSampler::CCVKSampler(Device *device) -: Sampler(device) { +CCVKSampler::CCVKSampler() +: Sampler() { } CCVKSampler::~CCVKSampler() { } -bool CCVKSampler::initialize(const SamplerInfo &info) { - _minFilter = info.minFilter; - _magFilter = info.magFilter; - _mipFilter = info.mipFilter; - _addressU = info.addressU; - _addressV = info.addressV; - _addressW = info.addressW; - _maxAnisotropy = info.maxAnisotropy; - _cmpFunc = info.cmpFunc; - _borderColor = info.borderColor; - _mipLODBias = info.mipLODBias; - +void CCVKSampler::doInit(const SamplerInfo &info) { _gpuSampler = CC_NEW(CCVKGPUSampler); _gpuSampler->minFilter = _minFilter; _gpuSampler->magFilter = _magFilter; @@ -63,15 +52,13 @@ bool CCVKSampler::initialize(const SamplerInfo &info) { _gpuSampler->borderColor = _borderColor; _gpuSampler->mipLODBias = _mipLODBias; - CCVKCmdFuncCreateSampler((CCVKDevice *)_device, _gpuSampler); - - return true; + CCVKCmdFuncCreateSampler(CCVKDevice::getInstance(), _gpuSampler); } -void CCVKSampler::destroy() { +void CCVKSampler::doDestroy() { if (_gpuSampler) { - ((CCVKDevice *)_device)->gpuDescriptorHub()->disengage(_gpuSampler); - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuSampler); + CCVKDevice::getInstance()->gpuDescriptorHub()->disengage(_gpuSampler); + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuSampler); _gpuSampler = nullptr; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKSampler.h b/native/cocos/renderer/gfx-vulkan/VKSampler.h index a9bb24f67f..0dd10b9124 100644 --- a/native/cocos/renderer/gfx-vulkan/VKSampler.h +++ b/native/cocos/renderer/gfx-vulkan/VKSampler.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_SAMPLER_H_ -#define CC_GFXVULKAN_SAMPLER_H_ +#pragma once #include "gfx-base/GFXSampler.h" @@ -35,20 +34,17 @@ class CCVKGPUSampler; class CC_VULKAN_API CCVKSampler final : public Sampler { public: - CCVKSampler(Device *device); + CCVKSampler(); ~CCVKSampler(); -public: - bool initialize(const SamplerInfo &info); - void destroy(); - CC_INLINE CCVKGPUSampler *gpuSampler() const { return _gpuSampler; } -private: +protected: + void doInit(const SamplerInfo &info) override; + void doDestroy() override; + CCVKGPUSampler *_gpuSampler = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKShader.cpp b/native/cocos/renderer/gfx-vulkan/VKShader.cpp index dac5704e92..4d0d2e8208 100644 --- a/native/cocos/renderer/gfx-vulkan/VKShader.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKShader.cpp @@ -32,21 +32,14 @@ namespace cc { namespace gfx { -CCVKShader::CCVKShader(Device *device) -: Shader(device) { +CCVKShader::CCVKShader() +: Shader() { } CCVKShader::~CCVKShader() { } -bool CCVKShader::initialize(const ShaderInfo &info) { - _name = info.name; - _stages = info.stages; - _attributes = info.attributes; - _blocks = info.blocks; - _buffers = info.buffers; - _samplers = info.samplers; - +void CCVKShader::doInit(const ShaderInfo &info) { _gpuShader = CC_NEW(CCVKGPUShader); _gpuShader->name = _name; _gpuShader->attributes = _attributes; @@ -56,14 +49,12 @@ bool CCVKShader::initialize(const ShaderInfo &info) { _gpuShader->gpuStages.push_back({stage.stage, stage.source}); } - CCVKCmdFuncCreateShader((CCVKDevice *)_device, _gpuShader); - - return true; + CCVKCmdFuncCreateShader(CCVKDevice::getInstance(), _gpuShader); } -void CCVKShader::destroy() { +void CCVKShader::doDestroy() { if (_gpuShader) { - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuShader); + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuShader); _gpuShader = nullptr; } } diff --git a/native/cocos/renderer/gfx-vulkan/VKShader.h b/native/cocos/renderer/gfx-vulkan/VKShader.h index 08370fcf58..144598e628 100644 --- a/native/cocos/renderer/gfx-vulkan/VKShader.h +++ b/native/cocos/renderer/gfx-vulkan/VKShader.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_SHADER_H_ -#define CC_GFXVULKAN_SHADER_H_ +#pragma once #include "gfx-base/GFXShader.h" @@ -35,20 +34,17 @@ class CCVKGPUShader; class CC_VULKAN_API CCVKShader final : public Shader { public: - CCVKShader(Device *device); + CCVKShader(); ~CCVKShader(); -public: - bool initialize(const ShaderInfo &info); - void destroy(); - CC_INLINE CCVKGPUShader *gpuShader() const { return _gpuShader; } -private: +protected: + void doInit(const ShaderInfo &info) override; + void doDestroy() override; + CCVKGPUShader *_gpuShader = nullptr; }; } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKTexture.cpp b/native/cocos/renderer/gfx-vulkan/VKTexture.cpp index d64d4db16d..73f4f83bf2 100644 --- a/native/cocos/renderer/gfx-vulkan/VKTexture.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKTexture.cpp @@ -33,65 +33,14 @@ namespace cc { namespace gfx { -CCVKTexture::CCVKTexture(Device *device) -: Texture(device) { +CCVKTexture::CCVKTexture() +: Texture() { } CCVKTexture::~CCVKTexture() { } -bool CCVKTexture::initialize(const TextureInfo &info) { - _type = info.type; - _usage = info.usage; - _format = info.format; - _width = info.width; - _height = info.height; - _depth = info.depth; - _layerCount = info.layerCount; - _levelCount = info.levelCount; - _samples = info.samples; - _flags = info.flags; - _size = FormatSize(_format, _width, _height, _depth); - -#if CC_DEBUG > 0 - switch (_format) { // device feature validation - case Format::D16: - if (_device->hasFeature(Feature::FORMAT_D16)) break; - CC_LOG_ERROR("D16 texture format is not supported on this backend"); - return false; - case Format::D16S8: - if (_device->hasFeature(Feature::FORMAT_D16S8)) break; - CC_LOG_WARNING("D16S8 texture format is not supported on this backend"); - return false; - case Format::D24: - if (_device->hasFeature(Feature::FORMAT_D24)) break; - CC_LOG_WARNING("D24 texture format is not supported on this backend"); - return false; - case Format::D24S8: - if (_device->hasFeature(Feature::FORMAT_D24S8)) break; - CC_LOG_WARNING("D24S8 texture format is not supported on this backend"); - return false; - case Format::D32F: - if (_device->hasFeature(Feature::FORMAT_D32F)) break; - CC_LOG_WARNING("D32F texture format is not supported on this backend"); - return false; - case Format::D32F_S8: - if (_device->hasFeature(Feature::FORMAT_D32FS8)) break; - CC_LOG_WARNING("D32FS8 texture format is not supported on this backend"); - return false; - case Format::RGB8: - if (_device->hasFeature(Feature::FORMAT_RGB8)) break; - CC_LOG_WARNING("RGB8 texture format is not supported on this backend"); - return false; - default: break; - } -#endif - - if (_flags & TextureFlags::BAKUP_BUFFER) { - _buffer = (uint8_t *)CC_MALLOC(_size); - _device->getMemoryStatus().textureSize += _size; - } - +void CCVKTexture::doInit(const TextureInfo &info) { _gpuTexture = CC_NEW(CCVKGPUTexture); _gpuTexture->type = _type; _gpuTexture->format = _format; @@ -106,42 +55,17 @@ bool CCVKTexture::initialize(const TextureInfo &info) { _gpuTexture->flags = _flags; _gpuTexture->isPowerOf2 = math::IsPowerOfTwo(_width) && math::IsPowerOfTwo(_height); - CCVKCmdFuncCreateTexture((CCVKDevice *)_device, _gpuTexture); - _device->getMemoryStatus().textureSize += _size; + CCVKCmdFuncCreateTexture(CCVKDevice::getInstance(), _gpuTexture); _gpuTextureView = CC_NEW(CCVKGPUTextureView); createTextureView(); - - return true; } -bool CCVKTexture::initialize(const TextureViewInfo &info) { - _isTextureView = true; - - if (!info.texture) { - return false; - } - - _type = info.texture->getType(); - _format = info.format; - _baseLayer = info.baseLayer; - _layerCount = info.layerCount; - _baseLevel = info.baseLevel; - _levelCount = info.levelCount; - _usage = info.texture->getUsage(); - _width = info.texture->getWidth(); - _height = info.texture->getHeight(); - _depth = info.texture->getDepth(); - _samples = info.texture->getSamples(); - _flags = info.texture->getFlags(); - _size = FormatSize(_format, _width, _height, _depth); - +void CCVKTexture::doInit(const TextureViewInfo &info) { _gpuTexture = ((CCVKTexture *)info.texture)->gpuTexture(); _gpuTextureView = CC_NEW(CCVKGPUTextureView); createTextureView(); - - return true; } void CCVKTexture::createTextureView() { @@ -152,67 +76,34 @@ void CCVKTexture::createTextureView() { _gpuTextureView->levelCount = _levelCount; _gpuTextureView->baseLayer = _baseLayer; _gpuTextureView->layerCount = _layerCount; - CCVKCmdFuncCreateTextureView((CCVKDevice *)_device, _gpuTextureView); + CCVKCmdFuncCreateTextureView(CCVKDevice::getInstance(), _gpuTextureView); } -void CCVKTexture::destroy() { +void CCVKTexture::doDestroy() { if (_gpuTextureView) { - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTextureView); - ((CCVKDevice *)_device)->gpuDescriptorHub()->disengage(_gpuTextureView); + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuTextureView); + CCVKDevice::getInstance()->gpuDescriptorHub()->disengage(_gpuTextureView); CC_DELETE(_gpuTextureView); _gpuTextureView = nullptr; } if (_gpuTexture) { if (!_isTextureView) { - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTexture); - ((CCVKDevice *)_device)->gpuBarrierManager()->cancel(_gpuTexture); - _device->getMemoryStatus().textureSize -= _size; + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuTexture); + CCVKDevice::getInstance()->gpuBarrierManager()->cancel(_gpuTexture); CC_DELETE(_gpuTexture); } _gpuTexture = nullptr; } - - if (_buffer) { - CC_FREE(_buffer); - _device->getMemoryStatus().textureSize -= _size; - _buffer = nullptr; - } } -void CCVKTexture::resize(uint width, uint height) { - CCASSERT(!_isTextureView, "Cannot resize texture views"); +void CCVKTexture::doResize(uint width, uint height) { + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuTextureView); + CCVKDevice::getInstance()->gpuRecycleBin()->collect(_gpuTexture); - if (_width != width || _height != height) { - uint size = FormatSize(_format, width, height, _depth); - const uint old_size = _size; - _width = width; - _height = height; - _size = size; + CCVKCmdFuncCreateTexture(CCVKDevice::getInstance(), _gpuTexture); - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTextureView); - ((CCVKDevice *)_device)->gpuRecycleBin()->collect(_gpuTexture); - - MemoryStatus &status = _device->getMemoryStatus(); - _gpuTexture->width = _width; - _gpuTexture->height = _height; - _gpuTexture->size = _size; - - CCVKCmdFuncCreateTexture((CCVKDevice *)_device, _gpuTexture); - status.bufferSize -= old_size; - status.bufferSize += _size; - - CCVKCmdFuncCreateTextureView((CCVKDevice *)_device, _gpuTextureView); - - if (_buffer) { - const uint8_t *old_buff = _buffer; - _buffer = (uint8_t *)CC_MALLOC(_size); - memcpy(_buffer, old_buff, old_size); - CC_FREE(_buffer); - status.bufferSize -= old_size; - status.bufferSize += _size; - } - } + CCVKCmdFuncCreateTextureView(CCVKDevice::getInstance(), _gpuTextureView); } } // namespace gfx diff --git a/native/cocos/renderer/gfx-vulkan/VKTexture.h b/native/cocos/renderer/gfx-vulkan/VKTexture.h index cf55faa24e..a6e7b98cc6 100644 --- a/native/cocos/renderer/gfx-vulkan/VKTexture.h +++ b/native/cocos/renderer/gfx-vulkan/VKTexture.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_TEXTURE_H_ -#define CC_GFXVULKAN_TEXTURE_H_ +#pragma once #include "gfx-base/GFXTexture.h" @@ -36,19 +35,18 @@ class CCVKGPUTextureView; class CC_VULKAN_API CCVKTexture final : public Texture { public: - CCVKTexture(Device *device); + CCVKTexture(); ~CCVKTexture(); -public: - bool initialize(const TextureInfo &info); - bool initialize(const TextureViewInfo &info); - void destroy(); - void resize(uint width, uint height); - CC_INLINE CCVKGPUTexture *gpuTexture() const { return _gpuTexture; } CC_INLINE CCVKGPUTextureView *gpuTextureView() const { return _gpuTextureView; } -private: +protected: + void doInit(const TextureInfo &info) override; + void doInit(const TextureViewInfo &info) override; + void doDestroy() override; + void doResize(uint width, uint height) override; + void createTextureView(); CCVKGPUTexture *_gpuTexture = nullptr; @@ -57,5 +55,3 @@ private: } // namespace gfx } // namespace cc - -#endif diff --git a/native/cocos/renderer/gfx-vulkan/VKTextureBarrier.cpp b/native/cocos/renderer/gfx-vulkan/VKTextureBarrier.cpp index 632d998f6e..13c836ca7c 100644 --- a/native/cocos/renderer/gfx-vulkan/VKTextureBarrier.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKTextureBarrier.cpp @@ -32,17 +32,15 @@ namespace cc { namespace gfx { -CCVKTextureBarrier::CCVKTextureBarrier(Device *device) -: TextureBarrier(device) { +CCVKTextureBarrier::CCVKTextureBarrier() +: TextureBarrier() { } CCVKTextureBarrier::~CCVKTextureBarrier() { CC_SAFE_DELETE(_gpuBarrier); } -bool CCVKTextureBarrier::initialize(const TextureBarrierInfo &info) { - _info = info; - +void CCVKTextureBarrier::doInit(const TextureBarrierInfo &info) { _gpuBarrier = CC_NEW(CCVKGPUTextureBarrier); _gpuBarrier->accessTypes.resize(info.prevAccesses.size() + info.nextAccesses.size()); @@ -73,8 +71,6 @@ bool CCVKTextureBarrier::initialize(const TextureBarrierInfo &info) { : VK_QUEUE_FAMILY_IGNORED; thsvsGetVulkanImageMemoryBarrier(_gpuBarrier->barrier, &_gpuBarrier->srcStageMask, &_gpuBarrier->dstStageMask, &_gpuBarrier->vkBarrier); - - return true; } } // namespace gfx diff --git a/native/cocos/renderer/gfx-vulkan/VKTextureBarrier.h b/native/cocos/renderer/gfx-vulkan/VKTextureBarrier.h index fee1a62a41..7e1fcb75e4 100644 --- a/native/cocos/renderer/gfx-vulkan/VKTextureBarrier.h +++ b/native/cocos/renderer/gfx-vulkan/VKTextureBarrier.h @@ -35,13 +35,13 @@ class CCVKGPUTextureBarrier; class CC_DLL CCVKTextureBarrier : public TextureBarrier { public: - CCVKTextureBarrier(Device *device); + CCVKTextureBarrier(); ~CCVKTextureBarrier(); CC_INLINE const CCVKGPUTextureBarrier *gpuBarrier() const { return _gpuBarrier; } protected: - bool initialize(const TextureBarrierInfo &info) override; + void doInit(const TextureBarrierInfo &info) override; CCVKGPUTextureBarrier *_gpuBarrier = nullptr; }; diff --git a/native/cocos/renderer/gfx-vulkan/VKUtils.h b/native/cocos/renderer/gfx-vulkan/VKUtils.h index 6823982656..f59a4e1304 100644 --- a/native/cocos/renderer/gfx-vulkan/VKUtils.h +++ b/native/cocos/renderer/gfx-vulkan/VKUtils.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef CC_GFXVULKAN_UTILS_H_ -#define CC_GFXVULKAN_UTILS_H_ +#pragma once #define WIN32_LEAN_AND_MEAN @@ -598,9 +597,7 @@ void fullPipelineBarrier(VkCommandBuffer cmdBuff) { memoryBarrier.srcAccessMask = FULL_ACCESS_FLAGS; memoryBarrier.dstAccessMask = FULL_ACCESS_FLAGS; vkCmdPipelineBarrier(cmdBuff, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - 0, 1, &memoryBarrier, 0, nullptr, 0, nullptr); -#endif -} + 0, 1, &memoryBarrier, 0, nullptr, 0, nullptr);} template char (*countofHelper(T (&_Array)[Size]))[Size]; diff --git a/native/cocos/renderer/pipeline/Define.cpp b/native/cocos/renderer/pipeline/Define.cpp index 022d4e5634..cea5c5c85b 100644 --- a/native/cocos/renderer/pipeline/Define.cpp +++ b/native/cocos/renderer/pipeline/Define.cpp @@ -30,10 +30,23 @@ namespace cc { namespace pipeline { + +int GLOBAL_UBO_COUNT = static_cast(PipelineGlobalBindings::SAMPLER_SHADOWMAP); +int GLOBAL_SAMPLER_COUNT = static_cast(PipelineGlobalBindings::COUNT) - GLOBAL_UBO_COUNT; + +int LOCAL_UBO_COUNT = static_cast(ModelLocalBindings::SAMPLER_JOINTS); +int LOCAL_SAMPLER_COUNT = static_cast(ModelLocalBindings::COUNT) - LOCAL_UBO_COUNT; + uint GLOBAL_SET = static_cast(SetIndex::GLOBAL); uint MATERIAL_SET = static_cast(SetIndex::MATERIAL); uint LOCAL_SET = static_cast(SetIndex::LOCAL); +gfx::BindingMappingInfo bindingMappingInfo = { + {0, GLOBAL_UBO_COUNT + LOCAL_UBO_COUNT, GLOBAL_UBO_COUNT}, + {-GLOBAL_UBO_COUNT, GLOBAL_SAMPLER_COUNT + LOCAL_SAMPLER_COUNT, GLOBAL_SAMPLER_COUNT - LOCAL_UBO_COUNT}, + 1, +}; + DescriptorSetLayoutInfos globalDescriptorSetLayout; DescriptorSetLayoutInfos localDescriptorSetLayout; const String UBOGlobal::NAME = "CCGlobal"; diff --git a/native/cocos/renderer/pipeline/Define.h b/native/cocos/renderer/pipeline/Define.h index 018c3594c3..f395f68215 100644 --- a/native/cocos/renderer/pipeline/Define.h +++ b/native/cocos/renderer/pipeline/Define.h @@ -27,8 +27,8 @@ #include -#include "base/Value.h" #include "base/Object.h" +#include "base/Value.h" #include "gfx-base/GFXDef.h" namespace cc { @@ -189,6 +189,9 @@ enum class CC_DLL PipelineGlobalBindings { COUNT, }; +extern CC_DLL int GLOBAL_UBO_COUNT; +extern CC_DLL int GLOBAL_SAMPLER_COUNT; + enum class CC_DLL ModelLocalBindings { UBO_LOCAL, UBO_FORWARD_LIGHTS, @@ -206,6 +209,21 @@ enum class CC_DLL ModelLocalBindings { COUNT, }; +extern CC_DLL int LOCAL_UBO_COUNT; +extern CC_DLL int LOCAL_SAMPLER_COUNT; + +enum class CC_DLL SetIndex { + GLOBAL, + MATERIAL, + LOCAL, +}; + +extern CC_DLL uint GLOBAL_SET; +extern CC_DLL uint MATERIAL_SET; +extern CC_DLL uint LOCAL_SET; + +extern CC_DLL gfx::BindingMappingInfo bindingMappingInfo; + struct CC_DLL UBOLocalBatched { static constexpr uint BATCHING_COUNT = 10; static constexpr uint MAT_WORLDS_OFFSET = 0; @@ -408,15 +426,7 @@ const uint CAMERA_DEFAULT_MASK = ~static_cast(LayerList::UI_2D) & ~static_ //constexpr CAMERA_DEFAULT_MASK = Layers.makeMaskExclude([Layers.BitMask.UI_2D, Layers.BitMask.GIZMOS, Layers.BitMask.EDITOR, // Layers.BitMask.SCENE_GIZMO, Layers.BitMask.PROFILER]); -uint nextPow2(uint val); -enum class CC_DLL SetIndex { - GLOBAL, - MATERIAL, - LOCAL, -}; -extern CC_DLL uint GLOBAL_SET; -extern CC_DLL uint MATERIAL_SET; -extern CC_DLL uint LOCAL_SET; +uint nextPow2(uint val); extern CC_DLL uint SKYBOX_FLAG; extern CC_DLL DescriptorSetLayoutInfos globalDescriptorSetLayout; @@ -519,5 +529,6 @@ struct CC_DLL SPRITE_TEXTURE : public Object { static const gfx::UniformSamplerTexture LAYOUT; static const String NAME; }; + } // namespace pipeline } // namespace cc diff --git a/native/tools/gfx-define-generator/generate.js b/native/tools/gfx-define-generator/generate.js index 61645c40b2..8706bfc549 100644 --- a/native/tools/gfx-define-generator/generate.js +++ b/native/tools/gfx-define-generator/generate.js @@ -37,7 +37,7 @@ if (options.engineRoot) { // TODO: remove this after state info refactor const ignoreList = { PipelineStateInfo: true, BlendTarget: true, BlendState: true, DepthStencilState: true, RasterizerState: true }; -let header = fs.readFileSync(`${__dirname}/../../cocos/renderer/core/gfx/GFXDef-common.h`).toString(); +let header = fs.readFileSync(ps.join(__dirname, '/../../cocos/renderer/gfx-base/GFXDef-common.h')).toString(); header = header.replace(/\r\n/g, '\n'); const enumRE = /enum\s+class\s+(\w+).*?{\s*?\n(.+?)};/gs; diff --git a/native/tools/tojs/genbindings.py b/native/tools/tojs/genbindings.py index 107d113425..a25b6e916f 100755 --- a/native/tools/tojs/genbindings.py +++ b/native/tools/tojs/genbindings.py @@ -144,37 +144,34 @@ def main(): output_dir = '%s/cocos/bindings/auto' % project_root cmd_args = { - 'cocos.ini' : ('cocos', 'jsb_cocos_auto'), - 'video.ini': ('video', 'jsb_video_auto'), - 'webview.ini': ('webview', 'jsb_webview_auto'), - 'audio.ini' : ('audio', 'jsb_audio_auto'), - 'extension.ini' : ('extension', 'jsb_extension_auto'), - 'network.ini' : ('network', 'jsb_network_auto'), - 'gfx.ini': ('gfx', 'jsb_gfx_auto'), - 'gles2.ini': ('gles2', 'jsb_gles2_auto'), - 'gles3.ini': ('gles3', 'jsb_gles3_auto'), - 'metal.ini': ('metal', 'jsb_mtl_auto'), - 'vulkan.ini': ('vulkan', 'jsb_vk_auto'), - 'pipeline.ini': ('pipeline', 'jsb_pipeline_auto'), - 'spine.ini': ('spine','jsb_spine_auto'), - 'editor_support.ini': ('editor_support','jsb_editor_support_auto'), - 'dragonbones.ini': ('dragonbones','jsb_dragonbones_auto') - } + 'cocos.ini' : ('cocos', 'jsb_cocos_auto'), + 'video.ini': ('video', 'jsb_video_auto'), + 'webview.ini': ('webview', 'jsb_webview_auto'), + 'audio.ini' : ('audio', 'jsb_audio_auto'), + 'extension.ini' : ('extension', 'jsb_extension_auto'), + 'network.ini' : ('network', 'jsb_network_auto'), + 'gfx.ini': ('gfx', 'jsb_gfx_auto'), + 'pipeline.ini': ('pipeline', 'jsb_pipeline_auto'), + 'spine.ini': ('spine','jsb_spine_auto'), + 'editor_support.ini': ('editor_support','jsb_editor_support_auto'), + 'dragonbones.ini': ('dragonbones','jsb_dragonbones_auto') + } + target = 'spidermonkey' generator_py = '%s/generator.py' % cxx_generator_root tasks = [] for key in cmd_args.keys(): - args = cmd_args[key] - cfg = '%s/%s' % (tojs_root, key) - print '!!----------Generating bindings for %s----------!!' % (key[:-4]) - command = '%s -W ignore %s %s -s %s -t %s -o %s -n %s' % (python_bin, generator_py, cfg, args[0], target, output_dir, args[1]) - # tasks.append(_run_cmd(command)) - _run_cmd(command).communicate() + if len(sys.argv) <= 1 or any(key[:-4] in s for s in sys.argv[1:]): + args = cmd_args[key] + cfg = '%s/%s' % (tojs_root, key) + print '!!----------Generating bindings for %s----------!!' % (key[:-4]) + command = '%s -W ignore %s %s -s %s -t %s -o %s -n %s' % (python_bin, generator_py, cfg, args[0], target, output_dir, args[1]) + # tasks.append(_run_cmd(command)) + _run_cmd(command).communicate() # for t in tasks: # t.communicate() - print '----------------------------------------' print 'Generating javascript bindings succeeds.' print '----------------------------------------' diff --git a/native/tools/tojs/gfx.ini b/native/tools/tojs/gfx.ini index 59ec26503d..f03e4b22d7 100644 --- a/native/tools/tojs/gfx.ini +++ b/native/tools/tojs/gfx.ini @@ -68,12 +68,12 @@ skip = Buffer::[Buffer getDevice initialize update], Sampler::[Sampler getDevice], Shader::[Shader getDevice], Texture::[Texture getDevice initialize], - Device::[copyBuffersToTexture createBuffer createTexture getInstance flushCommands$], + Device::[Device copyBuffersToTexture createBuffer createTexture getInstance flushCommands$], Context::[Context] -getter_setter = Device::[gfxAPI surfaceTransform deviceName width height nativeWidth nativeHeight memoryStatus context queue commandBuffer renderer vendor numDrawCalls numInstances numTris colorFormat depthStencilFormat capabilities], +getter_setter = Device::[gfxAPI surfaceTransform deviceName width height nativeWidth nativeHeight memoryStatus queue commandBuffer renderer vendor numDrawCalls numInstances numTris colorFormat depthStencilFormat capabilities], Shader::[name shaderID/getID stages attributes blocks samplers], - Texture::[type usage format width height depth layerCount levelCount size samples flags buffer], + Texture::[type usage format width height depth layerCount levelCount size samples flags], Queue::[type], RenderPass::[hash], PipelineState::[shader primitive bindPoint inputState rasterizerState depthStencilState blendState renderPass],