no message

This commit is contained in:
gem
2025-02-18 15:21:31 +08:00
commit 2d133e56d7
1980 changed files with 465595 additions and 0 deletions

View File

@@ -0,0 +1,170 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/memory/Memory.h"
#include <cstring>
#include "BufferAgent.h"
#include "DeviceAgent.h"
namespace cc {
namespace gfx {
BufferAgent::BufferAgent(Buffer *actor)
: Agent<Buffer>(actor) {
_typedID = actor->getTypedID();
}
BufferAgent::~BufferAgent() {
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
BufferDestruct,
actor, _actor,
stagingBuffer, std::move(_stagingBuffer),
{
CC_SAFE_DELETE(actor);
});
}
void BufferAgent::doInit(const BufferInfo &info) {
uint32_t size = getSize();
if (hasFlag(info.flags, BufferFlagBit::ENABLE_STAGING_WRITE) || (size > STAGING_BUFFER_THRESHOLD && hasFlag(_memUsage, MemoryUsageBit::HOST))) {
_stagingBuffer = std::make_unique<uint8_t[]>(size * DeviceAgent::MAX_FRAME_INDEX);
}
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
BufferInit,
actor, getActor(),
info, info,
{
actor->initialize(info);
});
}
void BufferAgent::doInit(const BufferViewInfo &info) {
BufferViewInfo actorInfo = info;
actorInfo.buffer = static_cast<BufferAgent *>(info.buffer)->getActor();
// buffer views don't need staging buffers
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
BufferViewInit,
actor, getActor(),
info, actorInfo,
{
actor->initialize(info);
});
}
void BufferAgent::doResize(uint32_t size, uint32_t /*count*/) {
auto *mq = DeviceAgent::getInstance()->getMessageQueue();
if (_stagingBuffer) {
ENQUEUE_MESSAGE_1(
mq, BufferFreeStagingBuffer,
stagingBuffer, std::move(_stagingBuffer),
{});
}
if (hasFlag(_flags, BufferFlagBit::ENABLE_STAGING_WRITE) || (size > STAGING_BUFFER_THRESHOLD && hasFlag(_memUsage, MemoryUsageBit::HOST))) {
_stagingBuffer = std::make_unique<uint8_t[]>(size * DeviceAgent::MAX_FRAME_INDEX);
}
ENQUEUE_MESSAGE_2(
mq, BufferResize,
actor, getActor(),
size, size,
{
actor->resize(size);
});
}
void BufferAgent::doDestroy() {
auto *mq = DeviceAgent::getInstance()->getMessageQueue();
ENQUEUE_MESSAGE_2(
mq, BufferDestroy,
actor, getActor(),
stagingBuffer, std::move(_stagingBuffer),
{
actor->destroy();
});
}
void BufferAgent::update(const void *buffer, uint32_t size) {
uint8_t *actorBuffer{nullptr};
bool needFreeing{false};
auto *mq{DeviceAgent::getInstance()->getMessageQueue()};
getActorBuffer(this, mq, size, &actorBuffer, &needFreeing);
memcpy(actorBuffer, buffer, size);
ENQUEUE_MESSAGE_4(
mq, BufferUpdate,
actor, getActor(),
buffer, actorBuffer,
size, size,
needFreeing, needFreeing,
{
actor->update(buffer, size);
if (needFreeing) free(buffer);
});
}
void BufferAgent::flush(const uint8_t *buffer) {
auto *mq = DeviceAgent::getInstance()->getMessageQueue();
ENQUEUE_MESSAGE_3(
mq, BufferUpdate,
actor, getActor(),
buffer, buffer,
size, _size,
{
actor->update(buffer, size);
});
}
void BufferAgent::getActorBuffer(const BufferAgent *buffer, MessageQueue *mq, uint32_t size, uint8_t **pActorBuffer, bool *pNeedFreeing) {
if (buffer->_stagingBuffer) { // for frequent updates on big buffers
uint32_t frameIndex = DeviceAgent::getInstance()->getCurrentIndex();
*pActorBuffer = buffer->_stagingBuffer.get() + frameIndex * buffer->_size;
} else if (size > STAGING_BUFFER_THRESHOLD) { // less frequent updates on big buffers
*pActorBuffer = reinterpret_cast<uint8_t *>(malloc(size));
*pNeedFreeing = true;
} else { // for small enough buffers
*pActorBuffer = mq->allocate<uint8_t>(size);
}
}
uint8_t *BufferAgent::getStagingAddress() const {
if (!_stagingBuffer) {
return nullptr;
}
uint32_t frameIndex = DeviceAgent::getInstance()->getCurrentIndex();
return _stagingBuffer.get() + _size * frameIndex;
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,61 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "base/threading/MessageQueue.h"
#include "gfx-base/GFXBuffer.h"
namespace cc {
class ThreadSafeLinearAllocator;
namespace gfx {
class CC_DLL BufferAgent final : public Agent<Buffer> {
public:
explicit BufferAgent(Buffer *actor);
~BufferAgent() override;
void update(const void *buffer, uint32_t size) override;
static void getActorBuffer(const BufferAgent *buffer, MessageQueue *mq, uint32_t size, uint8_t **pActorBuffer, bool *pNeedFreeing);
private:
void doInit(const BufferInfo &info) override;
void doInit(const BufferViewInfo &info) override;
void doResize(uint32_t size, uint32_t count) override;
void doDestroy() override;
void flush(const uint8_t *buffer) override;
uint8_t *getStagingAddress() const override;
static constexpr uint32_t STAGING_BUFFER_THRESHOLD = MessageQueue::MEMORY_CHUNK_SIZE / 2;
std::unique_ptr<uint8_t[]> _stagingBuffer;
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,595 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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 "CommandBufferAgent.h"
#include <cstring>
#include "BufferAgent.h"
#include "DescriptorSetAgent.h"
#include "DeviceAgent.h"
#include "FramebufferAgent.h"
#include "InputAssemblerAgent.h"
#include "PipelineStateAgent.h"
#include "QueryPoolAgent.h"
#include "QueueAgent.h"
#include "RenderPassAgent.h"
#include "TextureAgent.h"
#include "base/Utils.h"
#include "base/job-system/JobSystem.h"
#include "base/threading/MessageQueue.h"
#include "base/threading/ThreadSafeLinearAllocator.h"
namespace cc {
namespace gfx {
CommandBufferAgent::CommandBufferAgent(CommandBuffer *actor)
: Agent<CommandBuffer>(actor) {
_typedID = actor->getTypedID();
}
void CommandBufferAgent::flushCommands(uint32_t count, CommandBufferAgent *const *cmdBuffs, bool multiThreaded) {
// don't even touch the job system if we are only recording sequentially
if (count == 1) {
cmdBuffs[0]->getMessageQueue()->flushMessages();
return;
}
uint32_t jobThreadCount = JobSystem::getInstance()->threadCount();
uint32_t workForThisThread = (count - 1) / jobThreadCount + 1; // ceil(count / jobThreadCount)
if (count > workForThisThread + 1 && multiThreaded) { // more than one job to dispatch
JobGraph g(JobSystem::getInstance());
g.createForEachIndexJob(workForThisThread, count, 1U, [cmdBuffs](uint32_t i) {
cmdBuffs[i]->getMessageQueue()->flushMessages();
});
g.run();
for (uint32_t i = 0U; i < workForThisThread; ++i) {
cmdBuffs[i]->getMessageQueue()->flushMessages();
}
g.waitForAll();
} else {
for (uint32_t i = 0U; i < count; ++i) {
cmdBuffs[i]->getMessageQueue()->flushMessages();
}
}
}
CommandBufferAgent::~CommandBufferAgent() {
destroyMessageQueue();
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(), CommandBufferDestruct,
actor, _actor,
{
CC_SAFE_DELETE(actor);
});
}
void CommandBufferAgent::initMessageQueue() {
DeviceAgent *device = DeviceAgent::getInstance();
device->_cmdBuffRefs.insert(this);
_messageQueue = ccnew MessageQueue;
if (device->_multithreaded) _messageQueue->setImmediateMode(false);
}
void CommandBufferAgent::destroyMessageQueue() {
DeviceAgent::getInstance()->getMessageQueue()->kickAndWait();
CC_SAFE_DELETE(_messageQueue);
DeviceAgent::getInstance()->_cmdBuffRefs.erase(this);
}
void CommandBufferAgent::initAgent() {
initMessageQueue();
}
void CommandBufferAgent::destroyAgent() {
destroyMessageQueue();
}
void CommandBufferAgent::doInit(const CommandBufferInfo &info) {
initMessageQueue();
CommandBufferInfo actorInfo = info;
actorInfo.queue = static_cast<QueueAgent *>(info.queue)->getActor();
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(), CommandBufferInit,
actor, getActor(),
info, actorInfo,
{
actor->initialize(info);
});
}
void CommandBufferAgent::doDestroy() {
destroyMessageQueue();
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(), CommandBufferDestroy,
actor, getActor(),
{
actor->destroy();
});
}
void CommandBufferAgent::begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) {
ENQUEUE_MESSAGE_4(
_messageQueue,
CommandBufferBegin,
actor, getActor(),
renderPass, renderPass ? static_cast<RenderPassAgent *>(renderPass)->getActor() : nullptr,
subpass, subpass,
frameBuffer, frameBuffer ? static_cast<FramebufferAgent *>(frameBuffer)->getActor() : nullptr,
{
actor->begin(renderPass, subpass, frameBuffer);
});
}
void CommandBufferAgent::end() {
ENQUEUE_MESSAGE_1(
_messageQueue, CommandBufferEnd,
actor, getActor(),
{
actor->end();
});
}
void CommandBufferAgent::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) {
auto attachmentCount = utils::toUint(renderPass->getColorAttachments().size());
Color *actorColors = nullptr;
if (attachmentCount) {
actorColors = _messageQueue->allocate<Color>(attachmentCount);
memcpy(actorColors, colors, sizeof(Color) * attachmentCount);
}
CommandBuffer **actorSecondaryCBs = nullptr;
if (secondaryCBCount) {
actorSecondaryCBs = _messageQueue->allocate<CommandBuffer *>(secondaryCBCount);
for (uint32_t i = 0; i < secondaryCBCount; ++i) {
actorSecondaryCBs[i] = static_cast<CommandBufferAgent *>(secondaryCBs[i])->getActor();
}
}
ENQUEUE_MESSAGE_9(
_messageQueue, CommandBufferBeginRenderPass,
actor, getActor(),
renderPass, static_cast<RenderPassAgent *>(renderPass)->getActor(),
fbo, static_cast<FramebufferAgent *>(fbo)->getActor(),
renderArea, renderArea,
colors, actorColors,
depth, depth,
stencil, stencil,
secondaryCBCount, secondaryCBCount,
secondaryCBs, actorSecondaryCBs,
{
actor->beginRenderPass(renderPass, fbo, renderArea, colors, depth, stencil, secondaryCBs, secondaryCBCount);
});
}
void CommandBufferAgent::endRenderPass() {
ENQUEUE_MESSAGE_1(
_messageQueue, CommandBufferEndRenderPass,
actor, getActor(),
{
actor->endRenderPass();
});
}
void CommandBufferAgent::insertMarker(const MarkerInfo &marker) {
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferInsertMarker,
actor, getActor(),
marker, marker,
{
actor->insertMarker(marker);
});
}
void CommandBufferAgent::beginMarker(const MarkerInfo &marker) {
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferBeginMarker,
actor, getActor(),
marker, marker,
{
actor->beginMarker(marker);
});
}
void CommandBufferAgent::endMarker() {
ENQUEUE_MESSAGE_1(
_messageQueue, CommandBufferEndMarker,
actor, getActor(),
{
actor->endMarker();
});
}
void CommandBufferAgent::execute(CommandBuffer *const *cmdBuffs, uint32_t count) {
if (!count) return;
auto **actorCmdBuffs = _messageQueue->allocate<CommandBuffer *>(count);
for (uint32_t i = 0; i < count; ++i) {
actorCmdBuffs[i] = static_cast<CommandBufferAgent *>(cmdBuffs[i])->getActor();
}
ENQUEUE_MESSAGE_3(
_messageQueue, CommandBufferExecute,
actor, getActor(),
cmdBuffs, actorCmdBuffs,
count, count,
{
actor->execute(cmdBuffs, count);
});
}
void CommandBufferAgent::bindPipelineState(PipelineState *pso) {
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferBindPipelineState,
actor, getActor(),
pso, static_cast<PipelineStateAgent *>(pso)->getActor(),
{
actor->bindPipelineState(pso);
});
}
void CommandBufferAgent::bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) {
uint32_t *actorDynamicOffsets = nullptr;
if (dynamicOffsetCount) {
actorDynamicOffsets = _messageQueue->allocate<uint32_t>(dynamicOffsetCount);
memcpy(actorDynamicOffsets, dynamicOffsets, dynamicOffsetCount * sizeof(uint32_t));
}
ENQUEUE_MESSAGE_5(
_messageQueue, CommandBufferBindDescriptorSet,
actor, getActor(),
set, set,
descriptorSet, static_cast<DescriptorSetAgent *>(descriptorSet)->getActor(),
dynamicOffsetCount, dynamicOffsetCount,
dynamicOffsets, actorDynamicOffsets,
{
actor->bindDescriptorSet(set, descriptorSet, dynamicOffsetCount, dynamicOffsets);
});
}
void CommandBufferAgent::bindInputAssembler(InputAssembler *ia) {
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferBindInputAssembler,
actor, getActor(),
ia, static_cast<InputAssemblerAgent *>(ia)->getActor(),
{
actor->bindInputAssembler(ia);
});
}
void CommandBufferAgent::setViewport(const Viewport &vp) {
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferSetViewport,
actor, getActor(),
vp, vp,
{
actor->setViewport(vp);
});
}
void CommandBufferAgent::setScissor(const Rect &rect) {
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferSetScissor,
actor, getActor(),
rect, rect,
{
actor->setScissor(rect);
});
}
void CommandBufferAgent::setLineWidth(float width) {
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferSetLineWidth,
actor, getActor(),
width, width,
{
actor->setLineWidth(width);
});
}
void CommandBufferAgent::setDepthBias(float constant, float clamp, float slope) {
ENQUEUE_MESSAGE_4(
_messageQueue, CommandBufferSetDepthBias,
actor, getActor(),
constant, constant,
clamp, clamp,
slope, slope,
{
actor->setDepthBias(constant, clamp, slope);
});
}
void CommandBufferAgent::setBlendConstants(const Color &constants) {
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferSetBlendConstants,
actor, getActor(),
constants, constants,
{
actor->setBlendConstants(constants);
});
}
void CommandBufferAgent::setDepthBound(float minBounds, float maxBounds) {
ENQUEUE_MESSAGE_3(
_messageQueue, CommandBufferSetDepthBound,
actor, getActor(),
minBounds, minBounds,
maxBounds, maxBounds,
{
actor->setDepthBound(minBounds, maxBounds);
});
}
void CommandBufferAgent::setStencilWriteMask(StencilFace face, uint32_t mask) {
ENQUEUE_MESSAGE_3(
_messageQueue, CommandBufferSetStencilWriteMask,
actor, getActor(),
face, face,
mask, mask,
{
actor->setStencilWriteMask(face, mask);
});
}
void CommandBufferAgent::setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) {
ENQUEUE_MESSAGE_4(
_messageQueue, CommandBufferSetStencilCompareMask,
actor, getActor(),
face, face,
ref, ref,
mask, mask,
{
actor->setStencilCompareMask(face, ref, mask);
});
}
void CommandBufferAgent::nextSubpass() {
ENQUEUE_MESSAGE_1(
_messageQueue, CommandBufferNextSubpass,
actor, getActor(),
{
actor->nextSubpass();
});
}
void CommandBufferAgent::draw(const DrawInfo &info) {
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferDraw,
actor, getActor(),
info, info,
{
actor->draw(info);
});
}
void CommandBufferAgent::updateBuffer(Buffer *buff, const void *data, uint32_t size) {
auto *bufferAgent = static_cast<BufferAgent *>(buff);
uint8_t *actorBuffer{nullptr};
bool needFreeing{false};
BufferAgent::getActorBuffer(bufferAgent, _messageQueue, size, &actorBuffer, &needFreeing);
memcpy(actorBuffer, data, size);
ENQUEUE_MESSAGE_5(
_messageQueue, CommandBufferUpdateBuffer,
actor, getActor(),
buff, bufferAgent->getActor(),
data, actorBuffer,
size, size,
needFreeing, needFreeing,
{
actor->updateBuffer(buff, data, size);
if (needFreeing) free(data);
});
}
void CommandBufferAgent::resolveTexture(Texture *srcTexture, Texture *dstTexture, const TextureCopy *regions, uint32_t count) {
Texture *actorSrcTexture = nullptr;
Texture *actorDstTexture = nullptr;
if (srcTexture) actorSrcTexture = static_cast<TextureAgent *>(srcTexture)->getActor();
if (dstTexture) actorDstTexture = static_cast<TextureAgent *>(dstTexture)->getActor();
auto *actorRegions = _messageQueue->allocate<TextureCopy>(count);
memcpy(actorRegions, regions, count * sizeof(TextureCopy));
ENQUEUE_MESSAGE_5(
_messageQueue, CommandBufferBlitTexture,
actor, getActor(),
srcTexture, actorSrcTexture,
dstTexture, actorDstTexture,
regions, actorRegions,
count, count,
{
actor->resolveTexture(srcTexture, dstTexture, regions, count);
});
}
void CommandBufferAgent::copyTexture(Texture *srcTexture, Texture *dstTexture, const TextureCopy *regions, uint32_t count) {
Texture *actorSrcTexture = nullptr;
Texture *actorDstTexture = nullptr;
if (srcTexture) actorSrcTexture = static_cast<TextureAgent *>(srcTexture)->getActor();
if (dstTexture) actorDstTexture = static_cast<TextureAgent *>(dstTexture)->getActor();
auto *actorRegions = _messageQueue->allocate<TextureCopy>(count);
memcpy(actorRegions, regions, count * sizeof(TextureCopy));
ENQUEUE_MESSAGE_5(
_messageQueue, CommandBufferBlitTexture,
actor, getActor(),
srcTexture, actorSrcTexture,
dstTexture, actorDstTexture,
regions, actorRegions,
count, count,
{
actor->copyTexture(srcTexture, dstTexture, regions, count);
});
}
void CommandBufferAgent::blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) {
Texture *actorSrcTexture = nullptr;
Texture *actorDstTexture = nullptr;
if (srcTexture) actorSrcTexture = static_cast<TextureAgent *>(srcTexture)->getActor();
if (dstTexture) actorDstTexture = static_cast<TextureAgent *>(dstTexture)->getActor();
auto *actorRegions = _messageQueue->allocate<TextureBlit>(count);
memcpy(actorRegions, regions, count * sizeof(TextureBlit));
ENQUEUE_MESSAGE_6(
_messageQueue, CommandBufferBlitTexture,
actor, getActor(),
srcTexture, actorSrcTexture,
dstTexture, actorDstTexture,
regions, actorRegions,
count, count,
filter, filter,
{
actor->blitTexture(srcTexture, dstTexture, regions, count, filter);
});
}
void CommandBufferAgent::dispatch(const DispatchInfo &info) {
DispatchInfo actorInfo = info;
if (info.indirectBuffer) actorInfo.indirectBuffer = static_cast<BufferAgent *>(info.indirectBuffer)->getActor();
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferDispatch,
actor, getActor(),
info, actorInfo,
{
actor->dispatch(info);
});
}
void CommandBufferAgent::pipelineBarrier(const GeneralBarrier *barrier, const BufferBarrier *const *bufferBarriers, const Buffer *const *buffers, uint32_t bufferBarrierCount, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) {
TextureBarrier **actorTextureBarriers = nullptr;
Texture **actorTextures = nullptr;
BufferBarrier **actorBufferBarriers = nullptr;
Buffer **actorBuffers = nullptr;
if (textureBarrierCount) {
actorTextureBarriers = _messageQueue->allocate<TextureBarrier *>(textureBarrierCount);
memcpy(actorTextureBarriers, textureBarriers, textureBarrierCount * sizeof(uintptr_t));
actorTextures = _messageQueue->allocate<Texture *>(textureBarrierCount);
for (uint32_t i = 0U; i < textureBarrierCount; ++i) {
actorTextures[i] = textures[i] ? static_cast<const TextureAgent *>(textures[i])->getActor() : nullptr;
}
}
if (bufferBarrierCount) {
actorBufferBarriers = _messageQueue->allocateAndZero<BufferBarrier *>(bufferBarrierCount);
memcpy(actorBufferBarriers, bufferBarriers, bufferBarrierCount * sizeof(uintptr_t));
actorBuffers = _messageQueue->allocate<Buffer *>(bufferBarrierCount);
for (uint32_t i = 0; i < bufferBarrierCount; ++i) {
actorBuffers[i] = buffers[i] ? static_cast<const BufferAgent *>(buffers[i])->getActor() : nullptr;
}
}
ENQUEUE_MESSAGE_8(
_messageQueue, CommandBufferPipelineBarrier,
actor, getActor(),
barrier, barrier,
bufferBarriers, actorBufferBarriers,
buffers, actorBuffers,
bufferBarrierCount, bufferBarrierCount,
textureBarriers, actorTextureBarriers,
textures, actorTextures,
textureBarrierCount, textureBarrierCount,
{
actor->pipelineBarrier(barrier, bufferBarriers, buffers, bufferBarrierCount, textureBarriers, textures, textureBarrierCount);
});
}
void CommandBufferAgent::beginQuery(QueryPool *queryPool, uint32_t id) {
auto *actorQueryPool = static_cast<QueryPoolAgent *>(queryPool)->getActor();
ENQUEUE_MESSAGE_3(
_messageQueue, CommandBufferBeginQuery,
actor, getActor(),
queryPool, actorQueryPool,
id, id,
{
actor->beginQuery(queryPool, id);
});
}
void CommandBufferAgent::endQuery(QueryPool *queryPool, uint32_t id) {
auto *actorQueryPool = static_cast<QueryPoolAgent *>(queryPool)->getActor();
ENQUEUE_MESSAGE_3(
_messageQueue, CommandBufferEndQuery,
actor, getActor(),
queryPool, actorQueryPool,
id, id,
{
actor->endQuery(queryPool, id);
});
}
void CommandBufferAgent::resetQueryPool(QueryPool *queryPool) {
auto *actorQueryPool = static_cast<QueryPoolAgent *>(queryPool)->getActor();
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferResetQueryPool,
actor, getActor(),
queryPool, actorQueryPool,
{
actor->resetQueryPool(queryPool);
});
}
void CommandBufferAgent::completeQueryPool(QueryPool *queryPool) {
auto *actorQueryPool = static_cast<QueryPoolAgent *>(queryPool)->getActor();
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferCompleteQueryPool,
actor, getActor(),
queryPool, actorQueryPool,
{
actor->completeQueryPool(queryPool);
});
}
void CommandBufferAgent::customCommand(CustomCommand &&cmd) {
ENQUEUE_MESSAGE_2(
_messageQueue, CommandBufferCompleteQueryPool,
actor, getActor(),
cmd, cmd,
{
actor->customCommand(std::move(cmd));
});
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,98 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXCommandBuffer.h"
namespace cc {
class MessageQueue;
namespace gfx {
class CC_DLL CommandBufferAgent final : public Agent<CommandBuffer> {
public:
explicit CommandBufferAgent(CommandBuffer *actor);
~CommandBufferAgent() override;
static void flushCommands(uint32_t count, CommandBufferAgent *const *cmdBuffs, bool multiThreaded);
void begin(RenderPass *renderPass, uint32_t subpass, Framebuffer *frameBuffer) override;
void end() override;
void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, uint32_t stencil, CommandBuffer *const *secondaryCBs, uint32_t secondaryCBCount) override;
void endRenderPass() override;
void insertMarker(const MarkerInfo &marker) override;
void beginMarker(const MarkerInfo &marker) override;
void endMarker() override;
void bindPipelineState(PipelineState *pso) override;
void bindDescriptorSet(uint32_t set, DescriptorSet *descriptorSet, uint32_t dynamicOffsetCount, const uint32_t *dynamicOffsets) override;
void bindInputAssembler(InputAssembler *ia) override;
void setViewport(const Viewport &vp) override;
void setScissor(const Rect &rect) override;
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, uint32_t mask) override;
void setStencilCompareMask(StencilFace face, uint32_t ref, uint32_t mask) override;
void nextSubpass() override;
void draw(const DrawInfo &info) override;
void updateBuffer(Buffer *buff, const void *data, uint32_t size) override;
void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) override;
void blitTexture(Texture *srcTexture, Texture *dstTexture, const TextureBlit *regions, uint32_t count, Filter filter) override;
void copyTexture(Texture *srcTexture, Texture *dstTexture, const TextureCopy *regions, uint32_t count) override;
void resolveTexture(Texture *srcTexture, Texture *dstTexture, const TextureCopy *regions, uint32_t count) override;
void execute(CommandBuffer *const *cmdBuffs, uint32_t count) override;
void dispatch(const DispatchInfo &info) override;
void pipelineBarrier(const GeneralBarrier *barrier, const BufferBarrier *const *bufferBarriers, const Buffer *const *buffers, uint32_t bufferBarrierCount, const TextureBarrier *const *textureBarriers, const Texture *const *textures, uint32_t textureBarrierCount) override;
void beginQuery(QueryPool *queryPool, uint32_t id) override;
void endQuery(QueryPool *queryPool, uint32_t id) override;
void resetQueryPool(QueryPool *queryPool) override;
void completeQueryPool(QueryPool *queryPool) override;
void customCommand(CustomCommand &&cmd) override;
uint32_t getNumDrawCalls() const override { return _actor->getNumDrawCalls(); }
uint32_t getNumInstances() const override { return _actor->getNumInstances(); }
uint32_t getNumTris() const override { return _actor->getNumTris(); }
inline MessageQueue *getMessageQueue() { return _messageQueue; }
protected:
friend class DeviceAgent;
void initAgent();
void destroyAgent();
void doInit(const CommandBufferInfo &info) override;
void doDestroy() override;
void initMessageQueue();
void destroyMessageQueue();
MessageQueue *_messageQueue = nullptr;
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,149 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/threading/MessageQueue.h"
#include "BufferAgent.h"
#include "DescriptorSetAgent.h"
#include "DescriptorSetLayoutAgent.h"
#include "DeviceAgent.h"
#include "TextureAgent.h"
namespace cc {
namespace gfx {
DescriptorSetAgent::DescriptorSetAgent(DescriptorSet *actor)
: Agent<DescriptorSet>(actor) {
_typedID = actor->getTypedID();
}
DescriptorSetAgent::~DescriptorSetAgent() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
DescriptorSetDestruct,
actor, _actor,
{
CC_SAFE_DELETE(actor);
});
}
void DescriptorSetAgent::doInit(const DescriptorSetInfo &info) {
DescriptorSetInfo actorInfo;
actorInfo.layout = static_cast<const DescriptorSetLayoutAgent *>(info.layout)->getActor();
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
DescriptorSetInit,
actor, getActor(),
info, actorInfo,
{
actor->initialize(info);
});
}
void DescriptorSetAgent::doDestroy() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
DescriptorSetDestroy,
actor, getActor(),
{
actor->destroy();
});
}
void DescriptorSetAgent::update() {
// Avoid enqueueing unnecessary command
if (!_isDirty) return;
_isDirty = false;
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
DescriptorSetUpdate,
actor, getActor(),
{
actor->update();
});
}
void DescriptorSetAgent::forceUpdate() {
_isDirty = false;
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
DescriptorSetForceUpdate,
actor, getActor(),
{
actor->forceUpdate();
});
}
void DescriptorSetAgent::bindBuffer(uint32_t binding, Buffer *buffer, uint32_t index, AccessFlags flags) {
DescriptorSet::bindBuffer(binding, buffer, index, flags);
ENQUEUE_MESSAGE_5(
DeviceAgent::getInstance()->getMessageQueue(),
DescriptorSetBindBuffer,
actor, getActor(),
binding, binding,
buffer, static_cast<BufferAgent *>(buffer)->getActor(),
index, index,
flags, flags,
{
actor->bindBuffer(binding, buffer, index, flags);
});
}
void DescriptorSetAgent::bindTexture(uint32_t binding, Texture *texture, uint32_t index, AccessFlags flags) {
DescriptorSet::bindTexture(binding, texture, index, flags);
ENQUEUE_MESSAGE_5(
DeviceAgent::getInstance()->getMessageQueue(),
DescriptorSetBindTexture,
actor, getActor(),
binding, binding,
texture, static_cast<TextureAgent *>(texture)->getActor(),
index, index,
flags, flags,
{
actor->bindTexture(binding, texture, index, flags);
});
}
void DescriptorSetAgent::bindSampler(uint32_t binding, Sampler *sampler, uint32_t index) {
DescriptorSet::bindSampler(binding, sampler, index);
ENQUEUE_MESSAGE_4(
DeviceAgent::getInstance()->getMessageQueue(),
DescriptorSetBindSampler,
actor, getActor(),
binding, binding,
sampler, sampler,
index, index,
{
actor->bindSampler(binding, sampler, index);
});
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,51 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXDescriptorSet.h"
namespace cc {
namespace gfx {
class CC_DLL DescriptorSetAgent final : public Agent<DescriptorSet> {
public:
explicit DescriptorSetAgent(DescriptorSet *actor);
~DescriptorSetAgent() override;
void update() override;
void forceUpdate() override;
void bindBuffer(uint32_t binding, Buffer *buffer, uint32_t index, AccessFlags flags) override;
void bindTexture(uint32_t binding, Texture *texture, uint32_t index, AccessFlags flags) override;
void bindSampler(uint32_t binding, Sampler *sampler, uint32_t index) override;
protected:
void doInit(const DescriptorSetInfo &info) override;
void doDestroy() override;
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,70 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/threading/MessageQueue.h"
#include "DescriptorSetLayoutAgent.h"
#include "DeviceAgent.h"
namespace cc {
namespace gfx {
DescriptorSetLayoutAgent::DescriptorSetLayoutAgent(DescriptorSetLayout *actor)
: Agent<DescriptorSetLayout>(actor) {
_typedID = actor->getTypedID();
}
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

View File

@@ -0,0 +1,44 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXDescriptorSetLayout.h"
namespace cc {
namespace gfx {
class CC_DLL DescriptorSetLayoutAgent final : public Agent<DescriptorSetLayout> {
public:
explicit DescriptorSetLayoutAgent(DescriptorSetLayout *actor);
~DescriptorSetLayoutAgent() override;
protected:
void doInit(const DescriptorSetLayoutInfo &info) override;
void doDestroy() override;
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,463 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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 <boost/align/align_up.hpp>
#include <cstring>
#include "application/ApplicationManager.h"
#include "base/Log.h"
#include "base/threading/MessageQueue.h"
#include "base/threading/ThreadSafeLinearAllocator.h"
#include "platform/interfaces/modules/IXRInterface.h"
#include "BufferAgent.h"
#include "CommandBufferAgent.h"
#include "DescriptorSetAgent.h"
#include "DescriptorSetLayoutAgent.h"
#include "DeviceAgent.h"
#include "FramebufferAgent.h"
#include "InputAssemblerAgent.h"
#include "PipelineLayoutAgent.h"
#include "PipelineStateAgent.h"
#include "QueryPoolAgent.h"
#include "QueueAgent.h"
#include "RenderPassAgent.h"
#include "ShaderAgent.h"
#include "SwapchainAgent.h"
#include "TextureAgent.h"
namespace cc {
namespace gfx {
DeviceAgent *DeviceAgent::instance = nullptr;
DeviceAgent *DeviceAgent::getInstance() {
return DeviceAgent::instance;
}
DeviceAgent::DeviceAgent(Device *device) : Agent(device) {
DeviceAgent::instance = this;
}
DeviceAgent::~DeviceAgent() {
CC_SAFE_DELETE(_actor);
DeviceAgent::instance = nullptr;
}
bool DeviceAgent::doInit(const DeviceInfo &info) {
if (!_actor->initialize(info)) {
return false;
}
_xr = CC_GET_XR_INTERFACE();
_api = _actor->getGfxAPI();
_deviceName = _actor->getDeviceName();
_queue = ccnew QueueAgent(_actor->getQueue());
_queryPool = ccnew QueryPoolAgent(_actor->getQueryPool());
_cmdBuff = ccnew CommandBufferAgent(_actor->getCommandBuffer());
_renderer = _actor->getRenderer();
_vendor = _actor->getVendor();
_caps = _actor->_caps;
memcpy(_features.data(), _actor->_features.data(), static_cast<uint32_t>(Feature::COUNT) * sizeof(bool));
memcpy(_formatFeatures.data(), _actor->_formatFeatures.data(), static_cast<uint32_t>(Format::COUNT) * sizeof(FormatFeatureBit));
_mainMessageQueue = ccnew MessageQueue;
static_cast<CommandBufferAgent *>(_cmdBuff)->_queue = _queue;
static_cast<CommandBufferAgent *>(_cmdBuff)->initAgent();
setMultithreaded(true);
return true;
}
void DeviceAgent::doDestroy() {
if (!_mainMessageQueue) {
_actor->destroy();
} else {
ENQUEUE_MESSAGE_1(
_mainMessageQueue, DeviceDestroy,
actor, _actor,
{
actor->destroy();
});
}
if (_cmdBuff) {
static_cast<CommandBufferAgent *>(_cmdBuff)->destroyAgent();
static_cast<CommandBufferAgent *>(_cmdBuff)->_actor = nullptr;
delete _cmdBuff;
_cmdBuff = nullptr;
}
if (_queryPool) {
static_cast<QueryPoolAgent *>(_queryPool)->_actor = nullptr;
delete _queryPool;
_queryPool = nullptr;
}
if (_queue) {
static_cast<QueueAgent *>(_queue)->_actor = nullptr;
delete _queue;
_queue = nullptr;
}
if (_mainMessageQueue) {
_mainMessageQueue->terminateConsumerThread();
delete _mainMessageQueue;
_mainMessageQueue = nullptr;
}
}
void DeviceAgent::acquire(Swapchain *const *swapchains, uint32_t count) {
auto *actorSwapchains = _mainMessageQueue->allocate<Swapchain *>(count);
for (uint32_t i = 0; i < count; ++i) {
actorSwapchains[i] = static_cast<SwapchainAgent *>(swapchains[i])->getActor();
}
ENQUEUE_MESSAGE_4(
_mainMessageQueue, DevicePresent,
device, this,
actor, _actor,
swapchains, actorSwapchains,
count, count,
{
if (device->_onAcquire) device->_onAcquire->execute();
actor->acquire(swapchains, count);
});
}
void DeviceAgent::present() {
if (_xr) {
ENQUEUE_MESSAGE_1(
_mainMessageQueue, DevicePresent,
actor, _actor,
{
actor->present();
});
} else {
ENQUEUE_MESSAGE_2(
_mainMessageQueue, DevicePresent,
actor, _actor,
frameBoundarySemaphore, &_frameBoundarySemaphore,
{
actor->present();
frameBoundarySemaphore->signal();
});
MessageQueue::freeChunksInFreeQueue(_mainMessageQueue);
_mainMessageQueue->finishWriting();
_currentIndex = (_currentIndex + 1) % MAX_FRAME_INDEX;
_frameBoundarySemaphore.wait();
}
}
void DeviceAgent::setMultithreaded(bool multithreaded) {
if (multithreaded == _multithreaded) return;
_multithreaded = multithreaded;
if (multithreaded) {
_mainMessageQueue->setImmediateMode(false);
_actor->bindContext(false);
_mainMessageQueue->runConsumerThread();
ENQUEUE_MESSAGE_1(
_mainMessageQueue, DeviceMakeCurrentTrue,
actor, _actor,
{
actor->bindContext(true);
CC_LOG_INFO("Device thread detached.");
});
for (CommandBufferAgent *cmdBuff : _cmdBuffRefs) {
cmdBuff->_messageQueue->setImmediateMode(false);
}
} else {
ENQUEUE_MESSAGE_1(
_mainMessageQueue, DeviceMakeCurrentFalse,
actor, _actor,
{
actor->bindContext(false);
});
_mainMessageQueue->terminateConsumerThread();
_mainMessageQueue->setImmediateMode(true);
_actor->bindContext(true);
for (CommandBufferAgent *cmdBuff : _cmdBuffRefs) {
cmdBuff->_messageQueue->setImmediateMode(true);
}
CC_LOG_INFO("Device thread joined.");
}
}
CommandBuffer *DeviceAgent::createCommandBuffer(const CommandBufferInfo &info, bool /*hasAgent*/) {
CommandBuffer *actor = _actor->createCommandBuffer(info, true);
return ccnew CommandBufferAgent(actor);
}
Queue *DeviceAgent::createQueue() {
Queue *actor = _actor->createQueue();
return ccnew QueueAgent(actor);
}
QueryPool *DeviceAgent::createQueryPool() {
QueryPool *actor = _actor->createQueryPool();
return ccnew QueryPoolAgent(actor);
}
Swapchain *DeviceAgent::createSwapchain() {
Swapchain *actor = _actor->createSwapchain();
return ccnew SwapchainAgent(actor);
}
Buffer *DeviceAgent::createBuffer() {
Buffer *actor = _actor->createBuffer();
return ccnew BufferAgent(actor);
}
Texture *DeviceAgent::createTexture() {
Texture *actor = _actor->createTexture();
return ccnew TextureAgent(actor);
}
Shader *DeviceAgent::createShader() {
Shader *actor = _actor->createShader();
return ccnew ShaderAgent(actor);
}
InputAssembler *DeviceAgent::createInputAssembler() {
InputAssembler *actor = _actor->createInputAssembler();
return ccnew InputAssemblerAgent(actor);
}
RenderPass *DeviceAgent::createRenderPass() {
RenderPass *actor = _actor->createRenderPass();
return ccnew RenderPassAgent(actor);
}
Framebuffer *DeviceAgent::createFramebuffer() {
Framebuffer *actor = _actor->createFramebuffer();
return ccnew FramebufferAgent(actor);
}
DescriptorSet *DeviceAgent::createDescriptorSet() {
DescriptorSet *actor = _actor->createDescriptorSet();
return ccnew DescriptorSetAgent(actor);
}
DescriptorSetLayout *DeviceAgent::createDescriptorSetLayout() {
DescriptorSetLayout *actor = _actor->createDescriptorSetLayout();
return ccnew DescriptorSetLayoutAgent(actor);
}
PipelineLayout *DeviceAgent::createPipelineLayout() {
PipelineLayout *actor = _actor->createPipelineLayout();
return ccnew PipelineLayoutAgent(actor);
}
PipelineState *DeviceAgent::createPipelineState() {
PipelineState *actor = _actor->createPipelineState();
return ccnew PipelineStateAgent(actor);
}
Sampler *DeviceAgent::getSampler(const SamplerInfo &info) {
return _actor->getSampler(info);
}
GeneralBarrier *DeviceAgent::getGeneralBarrier(const GeneralBarrierInfo &info) {
return _actor->getGeneralBarrier(info);
}
TextureBarrier *DeviceAgent::getTextureBarrier(const TextureBarrierInfo &info) {
return _actor->getTextureBarrier(info);
}
BufferBarrier *DeviceAgent::getBufferBarrier(const BufferBarrierInfo &info) {
return _actor->getBufferBarrier(info);
}
template <typename T>
void doBufferTextureCopy(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count, MessageQueue *mq, T *actor) {
uint32_t bufferCount = 0U;
for (uint32_t i = 0U; i < count; i++) {
bufferCount += regions[i].texSubres.layerCount;
}
Format format = texture->getFormat();
constexpr uint32_t alignment = 16;
size_t totalSize = boost::alignment::align_up(sizeof(BufferTextureCopy) * count + sizeof(uint8_t *) * bufferCount, alignment);
for (uint32_t i = 0U; i < count; i++) {
const BufferTextureCopy &region = regions[i];
uint32_t size = formatSize(texture->getFormat(), region.texExtent.width, region.texExtent.height, region.texExtent.depth);
totalSize += boost::alignment::align_up(size, alignment) * region.texSubres.layerCount;
}
auto *allocator = ccnew ThreadSafeLinearAllocator(totalSize, alignment);
auto *actorRegions = allocator->allocate<BufferTextureCopy>(count);
memcpy(actorRegions, regions, count * sizeof(BufferTextureCopy));
const auto **actorBuffers = allocator->allocate<const uint8_t *>(bufferCount);
const auto blockHeight = formatAlignment(format).second;
for (uint32_t i = 0U, n = 0U; i < count; i++) {
const BufferTextureCopy &region = regions[i];
uint32_t width = region.texExtent.width;
uint32_t height = region.texExtent.height;
uint32_t depth = region.texExtent.depth;
uint32_t rowStride = region.buffStride > 0 ? region.buffStride : region.texExtent.width;
uint32_t heightStride = region.buffTexHeight > 0 ? region.buffTexHeight : region.texExtent.height;
uint32_t rowStrideSize = formatSize(format, rowStride, 1, 1);
uint32_t sliceStrideSize = formatSize(format, rowStride, heightStride, 1);
uint32_t destRowStrideSize = formatSize(format, width, 1, 1);
uint32_t size = formatSize(format, width, height, depth);
for (uint32_t l = 0; l < region.texSubres.layerCount; l++) {
auto *buffer = allocator->allocate<uint8_t>(size, alignment);
uint32_t destOffset = 0;
uint32_t buffOffset = 0;
for (uint32_t d = 0; d < depth; d++) {
buffOffset = region.buffOffset + sliceStrideSize * d;
for (uint32_t h = 0; h < height; h += blockHeight) {
memcpy(buffer + destOffset, buffers[n] + buffOffset, destRowStrideSize);
destOffset += destRowStrideSize;
buffOffset += rowStrideSize;
}
}
actorBuffers[n++] = buffer;
}
actorRegions[i].buffOffset = 0;
actorRegions[i].buffStride = 0;
actorRegions[i].buffTexHeight = 0;
}
ENQUEUE_MESSAGE_6(
mq, DeviceCopyBuffersToTexture,
actor, actor,
buffers, actorBuffers,
dst, static_cast<TextureAgent *>(texture)->getActor(),
regions, actorRegions,
count, count,
allocator, allocator,
{
actor->copyBuffersToTexture(buffers, dst, regions, count);
delete allocator;
});
}
void DeviceAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) {
doBufferTextureCopy(buffers, dst, regions, count, _mainMessageQueue, _actor);
}
void CommandBufferAgent::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint32_t count) {
doBufferTextureCopy(buffers, texture, regions, count, _messageQueue, _actor);
}
void DeviceAgent::copyTextureToBuffers(Texture *srcTexture, uint8_t *const *buffers, const BufferTextureCopy *regions, uint32_t count) {
ENQUEUE_MESSAGE_5(
_mainMessageQueue,
DeviceCopyTextureToBuffers,
actor, getActor(),
src, static_cast<TextureAgent *>(srcTexture)->getActor(),
buffers, buffers,
regions, regions,
count, count,
{
actor->copyTextureToBuffers(src, buffers, regions, count);
});
_mainMessageQueue->kickAndWait();
}
void DeviceAgent::flushCommands(CommandBuffer *const *cmdBuffs, uint32_t count) {
if (!_multithreaded) return; // all command buffers are immediately executed
auto **agentCmdBuffs = _mainMessageQueue->allocate<CommandBufferAgent *>(count);
for (uint32_t i = 0; i < count; ++i) {
agentCmdBuffs[i] = static_cast<CommandBufferAgent *const>(cmdBuffs[i]);
MessageQueue::freeChunksInFreeQueue(agentCmdBuffs[i]->_messageQueue);
agentCmdBuffs[i]->_messageQueue->finishWriting();
}
ENQUEUE_MESSAGE_3(
_mainMessageQueue, DeviceFlushCommands,
count, count,
cmdBuffs, agentCmdBuffs,
multiThreaded, _actor->_multithreadedCommandRecording,
{
CommandBufferAgent::flushCommands(count, cmdBuffs, multiThreaded);
});
}
void DeviceAgent::getQueryPoolResults(QueryPool *queryPool) {
QueryPool *actorQueryPool = static_cast<QueryPoolAgent *>(queryPool)->getActor();
ENQUEUE_MESSAGE_2(
_mainMessageQueue, DeviceGetQueryPoolResults,
actor, getActor(),
queryPool, actorQueryPool,
{
actor->getQueryPoolResults(queryPool);
});
auto *actorQueryPoolAgent = static_cast<QueryPoolAgent *>(actorQueryPool);
auto *queryPoolAgent = static_cast<QueryPoolAgent *>(queryPool);
std::lock_guard<std::mutex> lock(actorQueryPoolAgent->_mutex);
queryPoolAgent->_results = actorQueryPoolAgent->_results;
}
void DeviceAgent::enableAutoBarrier(bool en) {
ENQUEUE_MESSAGE_2(
_mainMessageQueue, enableAutoBarrier,
actor, getActor(),
en, en,
{
actor->enableAutoBarrier(en);
});
}
void DeviceAgent::presentSignal() {
_frameBoundarySemaphore.signal();
}
void DeviceAgent::presentWait() {
MessageQueue::freeChunksInFreeQueue(_mainMessageQueue);
_mainMessageQueue->finishWriting();
_currentIndex = (_currentIndex + 1) % MAX_FRAME_INDEX;
_frameBoundarySemaphore.wait();
}
void DeviceAgent::frameSync() {
ENQUEUE_MESSAGE_1(
_mainMessageQueue, FrameSync,
actor, _actor,
{
actor->frameSync();
});
}
SampleCount DeviceAgent::getMaxSampleCount(Format format, TextureUsage usage, TextureFlags flags) const {
return _actor->getMaxSampleCount(format, usage, flags);
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,136 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "base/std/container/unordered_set.h"
#include "base/threading/Semaphore.h"
#include "gfx-base/GFXDevice.h"
namespace cc {
class IXRInterface;
class MessageQueue;
namespace gfx {
class CommandBuffer;
class CommandBufferAgent;
class CC_DLL DeviceAgent final : public Agent<Device> {
public:
static DeviceAgent *getInstance();
static constexpr uint32_t MAX_CPU_FRAME_AHEAD = 1;
static constexpr uint32_t MAX_FRAME_INDEX = MAX_CPU_FRAME_AHEAD + 1;
~DeviceAgent() override;
using Device::copyBuffersToTexture;
using Device::createBuffer;
using Device::createCommandBuffer;
using Device::createDescriptorSet;
using Device::createDescriptorSetLayout;
using Device::createFramebuffer;
using Device::createGeneralBarrier;
using Device::createInputAssembler;
using Device::createPipelineLayout;
using Device::createPipelineState;
using Device::createQueryPool;
using Device::createQueue;
using Device::createRenderPass;
using Device::createSampler;
using Device::createShader;
using Device::createTexture;
using Device::createTextureBarrier;
void frameSync() override;
void acquire(Swapchain *const *swapchains, uint32_t count) override;
void present() override;
CommandBuffer *createCommandBuffer(const CommandBufferInfo &info, bool hasAgent) override;
Queue *createQueue() override;
QueryPool *createQueryPool() override;
Swapchain *createSwapchain() override;
Buffer *createBuffer() override;
Texture *createTexture() 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;
Sampler *getSampler(const SamplerInfo &info) override;
GeneralBarrier *getGeneralBarrier(const GeneralBarrierInfo &info) override;
TextureBarrier *getTextureBarrier(const TextureBarrierInfo &info) override;
BufferBarrier *getBufferBarrier(const BufferBarrierInfo &info) override;
void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint32_t count) override;
void copyTextureToBuffers(Texture *src, uint8_t *const *buffers, const BufferTextureCopy *region, uint32_t count) override;
void flushCommands(CommandBuffer *const *cmdBuffs, uint32_t count) override;
void getQueryPoolResults(QueryPool *queryPool) override;
MemoryStatus &getMemoryStatus() override { return _actor->getMemoryStatus(); }
uint32_t getNumDrawCalls() const override { return _actor->getNumDrawCalls(); }
uint32_t getNumInstances() const override { return _actor->getNumInstances(); }
uint32_t getNumTris() const override { return _actor->getNumTris(); }
uint32_t getCurrentIndex() const { return _currentIndex; }
void setMultithreaded(bool multithreaded);
inline MessageQueue *getMessageQueue() const { return _mainMessageQueue; }
void presentWait();
void presentSignal();
void enableAutoBarrier(bool en) override;
SampleCount getMaxSampleCount(Format format, TextureUsage usage, TextureFlags flags) const override;
protected:
static DeviceAgent *instance;
friend class DeviceManager;
friend class CommandBufferAgent;
explicit DeviceAgent(Device *device);
bool doInit(const DeviceInfo &info) override;
void doDestroy() override;
bool _multithreaded{false};
MessageQueue *_mainMessageQueue{nullptr};
uint32_t _currentIndex = 0U;
#if CC_USE_XR
Semaphore _frameBoundarySemaphore{0};
#else
Semaphore _frameBoundarySemaphore{MAX_CPU_FRAME_AHEAD};
#endif
ccstd::unordered_set<CommandBufferAgent *> _cmdBuffRefs;
IXRInterface *_xr{nullptr};
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,86 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/threading/MessageQueue.h"
#include "DeviceAgent.h"
#include "FramebufferAgent.h"
#include "RenderPassAgent.h"
#include "TextureAgent.h"
namespace cc {
namespace gfx {
FramebufferAgent::FramebufferAgent(Framebuffer *actor)
: Agent<Framebuffer>(actor) {
_typedID = actor->getTypedID();
}
FramebufferAgent::~FramebufferAgent() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
FramebufferDestruct,
actor, _actor,
{
CC_SAFE_DELETE(actor);
});
}
void FramebufferAgent::doInit(const FramebufferInfo &info) {
FramebufferInfo actorInfo = info;
for (uint32_t i = 0U; i < info.colorTextures.size(); ++i) {
if (info.colorTextures[i]) {
actorInfo.colorTextures[i] = static_cast<TextureAgent *>(info.colorTextures[i])->getActor();
}
}
if (info.depthStencilTexture) {
actorInfo.depthStencilTexture = static_cast<TextureAgent *>(info.depthStencilTexture)->getActor();
}
if (info.depthStencilResolveTexture) {
actorInfo.depthStencilResolveTexture = static_cast<TextureAgent *>(info.depthStencilResolveTexture)->getActor();
}
actorInfo.renderPass = static_cast<RenderPassAgent *>(info.renderPass)->getActor();
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
FramebufferInit,
actor, getActor(),
info, actorInfo,
{
actor->initialize(info);
});
}
void FramebufferAgent::doDestroy() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
FramebufferDestroy,
actor, getActor(),
{
actor->destroy();
});
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,44 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXFramebuffer.h"
namespace cc {
namespace gfx {
class CC_DLL FramebufferAgent final : public Agent<Framebuffer> {
public:
explicit FramebufferAgent(Framebuffer *actor);
~FramebufferAgent() override;
protected:
void doInit(const FramebufferInfo &info) override;
void doDestroy() override;
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,82 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/threading/MessageQueue.h"
#include "BufferAgent.h"
#include "DeviceAgent.h"
#include "InputAssemblerAgent.h"
namespace cc {
namespace gfx {
InputAssemblerAgent::InputAssemblerAgent(InputAssembler *actor)
: Agent<InputAssembler>(actor) {
_typedID = actor->getTypedID();
}
InputAssemblerAgent::~InputAssemblerAgent() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
InputAssemblerDestruct,
actor, _actor,
{
CC_SAFE_DELETE(actor);
});
}
void InputAssemblerAgent::doInit(const InputAssemblerInfo &info) {
InputAssemblerInfo actorInfo = info;
for (auto &vertexBuffer : actorInfo.vertexBuffers) {
vertexBuffer = static_cast<BufferAgent *>(vertexBuffer)->getActor();
}
if (actorInfo.indexBuffer) {
actorInfo.indexBuffer = static_cast<BufferAgent *>(actorInfo.indexBuffer)->getActor();
}
if (actorInfo.indirectBuffer) {
actorInfo.indirectBuffer = static_cast<BufferAgent *>(actorInfo.indirectBuffer)->getActor();
}
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
InputAssemblerInit,
actor, getActor(),
info, actorInfo,
{
actor->initialize(info);
});
}
void InputAssemblerAgent::doDestroy() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
InputAssemblerDestroy,
actor, getActor(),
{
actor->destroy();
});
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,44 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXInputAssembler.h"
namespace cc {
namespace gfx {
class CC_DLL InputAssemblerAgent final : public Agent<InputAssembler> {
public:
explicit InputAssemblerAgent(InputAssembler *actor);
~InputAssemblerAgent() override;
protected:
void doInit(const InputAssemblerInfo &info) override;
void doDestroy() override;
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,77 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/threading/MessageQueue.h"
#include "DescriptorSetLayoutAgent.h"
#include "DeviceAgent.h"
#include "PipelineLayoutAgent.h"
namespace cc {
namespace gfx {
PipelineLayoutAgent::PipelineLayoutAgent(PipelineLayout *actor)
: Agent<PipelineLayout>(actor) {
_typedID = actor->getTypedID();
}
PipelineLayoutAgent::~PipelineLayoutAgent() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
PipelineLayoutDestruct,
actor, _actor,
{
CC_SAFE_DELETE(actor);
});
}
void PipelineLayoutAgent::doInit(const PipelineLayoutInfo &info) {
PipelineLayoutInfo actorInfo;
actorInfo.setLayouts.resize(info.setLayouts.size());
for (uint32_t i = 0U; i < info.setLayouts.size(); i++) {
actorInfo.setLayouts[i] = static_cast<DescriptorSetLayoutAgent *>(info.setLayouts[i])->getActor();
}
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
PipelineLayoutInit,
actor, getActor(),
info, actorInfo,
{
actor->initialize(info);
});
}
void PipelineLayoutAgent::doDestroy() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
PipelineLayoutDestroy,
actor, getActor(),
{
actor->destroy();
});
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,44 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXPipelineLayout.h"
namespace cc {
namespace gfx {
class CC_DLL PipelineLayoutAgent final : public Agent<PipelineLayout> {
public:
explicit PipelineLayoutAgent(PipelineLayout *actor);
~PipelineLayoutAgent() override;
protected:
void doInit(const PipelineLayoutInfo &info) override;
void doDestroy() override;
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,78 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/threading/MessageQueue.h"
#include "DeviceAgent.h"
#include "PipelineLayoutAgent.h"
#include "PipelineStateAgent.h"
#include "RenderPassAgent.h"
#include "ShaderAgent.h"
namespace cc {
namespace gfx {
PipelineStateAgent::PipelineStateAgent(PipelineState *actor)
: Agent<PipelineState>(actor) {
_typedID = actor->getTypedID();
}
PipelineStateAgent::~PipelineStateAgent() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
PipelineStateDestruct,
actor, _actor,
{
CC_SAFE_DELETE(actor);
});
}
void PipelineStateAgent::doInit(const PipelineStateInfo &info) {
PipelineStateInfo actorInfo = info;
actorInfo.shader = static_cast<ShaderAgent *>(info.shader)->getActor();
actorInfo.pipelineLayout = static_cast<PipelineLayoutAgent *>(info.pipelineLayout)->getActor();
if (info.renderPass) actorInfo.renderPass = static_cast<RenderPassAgent *>(info.renderPass)->getActor();
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
PipelineStateInit,
actor, getActor(),
info, actorInfo,
{
actor->initialize(info);
});
}
void PipelineStateAgent::doDestroy() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
PipelineStateDestroy,
actor, getActor(),
{
actor->destroy();
});
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,44 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXPipelineState.h"
namespace cc {
namespace gfx {
class CC_DLL PipelineStateAgent final : public Agent<PipelineState> {
public:
explicit PipelineStateAgent(PipelineState *actor);
~PipelineStateAgent() override;
protected:
void doInit(const PipelineStateInfo &info) override;
void doDestroy() override;
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,74 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/job-system/JobSystem.h"
#include "base/threading/MessageQueue.h"
#include "CommandBufferAgent.h"
#include "DeviceAgent.h"
#include "QueryPoolAgent.h"
namespace cc {
namespace gfx {
QueryPoolAgent::QueryPoolAgent(QueryPool *actor)
: Agent<QueryPool>(actor) {
_typedID = actor->getTypedID();
_type = actor->getType();
_maxQueryObjects = actor->getMaxQueryObjects();
}
QueryPoolAgent::~QueryPoolAgent() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
QueryDestruct,
actor, _actor,
{
CC_SAFE_DELETE(actor);
});
}
void QueryPoolAgent::doInit(const QueryPoolInfo &info) {
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
QueryInit,
actor, getActor(),
info, info,
{
actor->initialize(info);
});
}
void QueryPoolAgent::doDestroy() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
QueryDestroy,
actor, getActor(),
{
actor->destroy();
});
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,46 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXQueryPool.h"
namespace cc {
namespace gfx {
class CC_DLL QueryPoolAgent final : public Agent<QueryPool> {
public:
explicit QueryPoolAgent(QueryPool *actor);
~QueryPoolAgent() override;
protected:
friend class DeviceAgent;
void doInit(const QueryPoolInfo &info) override;
void doDestroy() override;
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,103 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/job-system/JobSystem.h"
#include "base/threading/MessageQueue.h"
#include "CommandBufferAgent.h"
#include "DeviceAgent.h"
#include "QueueAgent.h"
namespace cc {
namespace gfx {
QueueAgent::QueueAgent(Queue *actor)
: Agent<Queue>(actor) {
_typedID = actor->getTypedID();
}
QueueAgent::~QueueAgent() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
QueueDestruct,
actor, _actor,
{
CC_SAFE_DELETE(actor);
});
}
void QueueAgent::doInit(const QueueInfo &info) {
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
QueueInit,
actor, getActor(),
info, info,
{
actor->initialize(info);
});
}
void QueueAgent::doDestroy() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
QueueDestroy,
actor, getActor(),
{
actor->destroy();
});
}
void QueueAgent::submit(CommandBuffer *const *cmdBuffs, uint32_t count) {
if (!count) return;
MessageQueue *msgQ = DeviceAgent::getInstance()->getMessageQueue();
auto **actorCmdBuffs = msgQ->allocate<CommandBuffer *>(count);
for (uint32_t i = 0U; i < count; ++i) {
actorCmdBuffs[i] = static_cast<CommandBufferAgent *>(cmdBuffs[i])->getActor();
}
ENQUEUE_MESSAGE_3(
DeviceAgent::getInstance()->getMessageQueue(),
QueueSubmit,
actor, getActor(),
actorCmdBuffs, actorCmdBuffs,
count, count,
{
//auto startTime = std::chrono::steady_clock::now();
//auto endTime = std::chrono::steady_clock::now();
//float dt = std::chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime).count() / 1e6;
//static float timeAcc = 0.f;
//if (!timeAcc) timeAcc = dt;
//else timeAcc = timeAcc * 0.95f + dt * 0.05f;
//CC_LOG_INFO("---------- %.2fms", timeAcc);
//CC_LOG_INFO("======== one round ========");
actor->submit(actorCmdBuffs, count);
});
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,50 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXQueue.h"
namespace cc {
namespace gfx {
class CC_DLL QueueAgent final : public Agent<Queue> {
public:
using Queue::submit;
explicit QueueAgent(Queue *actor);
~QueueAgent() override;
void submit(CommandBuffer *const *cmdBuffs, uint32_t count) override;
protected:
friend class DeviceAgent;
void doInit(const QueueInfo &info) override;
void doDestroy() override;
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,70 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/threading/MessageQueue.h"
#include "DeviceAgent.h"
#include "RenderPassAgent.h"
namespace cc {
namespace gfx {
RenderPassAgent::RenderPassAgent(RenderPass *actor)
: Agent<RenderPass>(actor) {
_typedID = actor->getTypedID();
}
RenderPassAgent::~RenderPassAgent() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
RenderPassDestruct,
actor, _actor,
{
CC_SAFE_DELETE(actor);
});
}
void RenderPassAgent::doInit(const RenderPassInfo &info) {
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
RenderPassInit,
actor, getActor(),
info, info,
{
actor->initialize(info);
});
}
void RenderPassAgent::doDestroy() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
RenderPassDestroy,
actor, getActor(),
{
actor->destroy();
});
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,44 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXRenderPass.h"
namespace cc {
namespace gfx {
class CC_DLL RenderPassAgent final : public Agent<RenderPass> {
public:
explicit RenderPassAgent(RenderPass *actor);
~RenderPassAgent() override;
protected:
void doInit(const RenderPassInfo &info) override;
void doDestroy() override;
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,70 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/threading/MessageQueue.h"
#include "DeviceAgent.h"
#include "ShaderAgent.h"
namespace cc {
namespace gfx {
ShaderAgent::ShaderAgent(Shader *actor)
: Agent<Shader>(actor) {
_typedID = actor->getTypedID();
}
ShaderAgent::~ShaderAgent() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
ShaderDestruct,
actor, _actor,
{
CC_SAFE_DELETE(actor);
});
}
void ShaderAgent::doInit(const ShaderInfo &info) {
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
ShaderInit,
actor, getActor(),
info, info,
{
actor->initialize(info);
});
}
void ShaderAgent::doDestroy() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
ShaderDestroy,
actor, getActor(),
{
actor->destroy();
});
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,44 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXShader.h"
namespace cc {
namespace gfx {
class CC_DLL ShaderAgent final : public Agent<Shader> {
public:
explicit ShaderAgent(Shader *actor);
~ShaderAgent() override;
protected:
void doInit(const ShaderInfo &info) override;
void doDestroy() override;
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,151 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/threading/MessageQueue.h"
#include "DeviceAgent.h"
#include "SwapchainAgent.h"
#include "gfx-agent/TextureAgent.h"
namespace cc {
namespace gfx {
SwapchainAgent::SwapchainAgent(Swapchain *actor)
: Agent<Swapchain>(actor) {
_typedID = actor->getTypedID();
_preRotationEnabled = static_cast<SwapchainAgent *>(actor)->_preRotationEnabled;
}
SwapchainAgent::~SwapchainAgent() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(), SwapchainDestruct,
actor, _actor,
{
CC_SAFE_DELETE(actor);
});
}
void SwapchainAgent::doInit(const SwapchainInfo &info) {
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(), SwapchainInit,
actor, getActor(),
info, info,
{
actor->initialize(info);
});
DeviceAgent::getInstance()->getMessageQueue()->kickAndWait();
auto *colorTexture = ccnew TextureAgent(_actor->getColorTexture());
colorTexture->renounceOwnership();
_colorTexture = colorTexture;
auto *depthStencilTexture = ccnew TextureAgent(_actor->getDepthStencilTexture());
depthStencilTexture->renounceOwnership();
_depthStencilTexture = depthStencilTexture;
SwapchainTextureInfo textureInfo;
textureInfo.swapchain = this;
textureInfo.format = _actor->getColorTexture()->getFormat();
textureInfo.width = _actor->getWidth();
textureInfo.height = _actor->getHeight();
initTexture(textureInfo, _colorTexture);
textureInfo.format = _actor->getDepthStencilTexture()->getFormat();
initTexture(textureInfo, _depthStencilTexture);
_transform = _actor->getSurfaceTransform();
}
void SwapchainAgent::doDestroy() {
_depthStencilTexture = nullptr;
_colorTexture = nullptr;
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(), SwapchainDestroy,
actor, getActor(),
{
actor->destroy();
});
}
void SwapchainAgent::doResize(uint32_t width, uint32_t height, SurfaceTransform transform) {
auto *mq = DeviceAgent::getInstance()->getMessageQueue();
ENQUEUE_MESSAGE_4(
mq, SwapchainResize,
actor, getActor(),
width, width,
height, height,
transform, transform,
{
actor->resize(width, height, transform);
});
mq->kickAndWait();
updateInfo();
}
void SwapchainAgent::updateInfo() {
_generation = _actor->getGeneration();
SwapchainTextureInfo textureInfo;
textureInfo.swapchain = this;
textureInfo.format = _actor->getColorTexture()->getFormat();
textureInfo.width = _actor->getWidth();
textureInfo.height = _actor->getHeight();
updateTextureInfo(textureInfo, _colorTexture);
textureInfo.format = _actor->getDepthStencilTexture()->getFormat();
updateTextureInfo(textureInfo, _depthStencilTexture);
_transform = _actor->getSurfaceTransform();
}
void SwapchainAgent::doDestroySurface() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(), SwapchaindestroySurface,
actor, getActor(),
{
actor->destroySurface();
});
DeviceAgent::getInstance()->getMessageQueue()->kickAndWait();
}
void SwapchainAgent::doCreateSurface(void *windowHandle) {
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(), SwapchaincreateSurface,
actor, getActor(),
windowHandle, windowHandle,
{
actor->createSurface(windowHandle);
});
DeviceAgent::getInstance()->getMessageQueue()->kickAndWait();
updateInfo();
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,48 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXSwapchain.h"
namespace cc {
namespace gfx {
class CC_DLL SwapchainAgent final : public Agent<Swapchain> {
public:
explicit SwapchainAgent(Swapchain *actor);
~SwapchainAgent() override;
protected:
void doInit(const SwapchainInfo &info) override;
void doDestroy() override;
void doResize(uint32_t width, uint32_t height, SurfaceTransform transform) override;
void doDestroySurface() override;
void doCreateSurface(void *windowHandle) override;
void updateInfo();
};
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,104 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/threading/MessageQueue.h"
#include "DeviceAgent.h"
#include "TextureAgent.h"
#include "gfx-agent/SwapchainAgent.h"
#include "gfx-base/GFXDef.h"
namespace cc {
namespace gfx {
TextureAgent::TextureAgent(Texture *actor)
: Agent<Texture>(actor) {
_typedID = actor->getTypedID();
}
TextureAgent::~TextureAgent() {
if (_ownTheActor) {
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 = static_cast<TextureAgent *>(info.texture)->getActor();
ENQUEUE_MESSAGE_2(
DeviceAgent::getInstance()->getMessageQueue(),
TextureViewInit,
actor, getActor(),
info, actorInfo,
{
actor->initialize(info);
});
}
void TextureAgent::doInit(const SwapchainTextureInfo &info) {
// the actor is already initialized
}
void TextureAgent::doDestroy() {
ENQUEUE_MESSAGE_1(
DeviceAgent::getInstance()->getMessageQueue(),
TextureDestroy,
actor, getActor(),
{
actor->destroy();
});
}
void TextureAgent::doResize(uint32_t width, uint32_t height, uint32_t /*size*/) {
ENQUEUE_MESSAGE_3(
DeviceAgent::getInstance()->getMessageQueue(),
TextureResize,
actor, getActor(),
width, width,
height, height,
{
actor->resize(width, height);
});
}
} // namespace gfx
} // namespace cc

View File

@@ -0,0 +1,57 @@
/****************************************************************************
Copyright (c) 2020-2023 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 documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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/Agent.h"
#include "gfx-base/GFXTexture.h"
namespace cc {
namespace gfx {
class CC_DLL TextureAgent : public Agent<Texture> {
public:
explicit TextureAgent(Texture *actor);
~TextureAgent() override;
inline void renounceOwnership() { _ownTheActor = false; }
const Texture *getRaw() const override { return _actor->getRaw(); }
uint32_t getGLTextureHandle() const noexcept override { return _actor->getGLTextureHandle(); }
protected:
friend class SwapchainAgent;
void doInit(const TextureInfo &info) override;
void doInit(const TextureViewInfo &info) override;
void doInit(const SwapchainTextureInfo &info) override;
void doDestroy() override;
void doResize(uint32_t width, uint32_t height, uint32_t size) override;
bool _ownTheActor = true;
};
} // namespace gfx
} // namespace cc