Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
YunHsiao committed Aug 24, 2020
1 parent ac37e3f commit 03d9f9e
Show file tree
Hide file tree
Showing 28 changed files with 159 additions and 112 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,6 @@ endif()
if(CC_USE_METAL)
cocos_source_files(
cocos/renderer/gfx-metal/GFXMTL.h
cocos/renderer/gfx-metal/MTLBindingLayout.cpp
cocos/renderer/gfx-metal/MTLBindingLayout.h
cocos/renderer/gfx-metal/MTLBuffer.h
cocos/renderer/gfx-metal/MTLBuffer.mm
cocos/renderer/gfx-metal/MTLCommandBuffer.h
Expand All @@ -688,8 +686,14 @@ if(CC_USE_METAL)
cocos/renderer/gfx-metal/MTLGPUObjects.h
cocos/renderer/gfx-metal/MTLInputAssembler.h
cocos/renderer/gfx-metal/MTLInputAssembler.mm
cocos/renderer/gfx-metal/MTLDescriptorSetLayout.h
cocos/renderer/gfx-metal/MTLDescriptorSetLayout.mm
cocos/renderer/gfx-metal/MTLPipelineLayout.h
cocos/renderer/gfx-metal/MTLPipelineLayout.mm
cocos/renderer/gfx-metal/MTLPipelineState.h
cocos/renderer/gfx-metal/MTLPipelineState.mm
cocos/renderer/gfx-metal/MTLDescriptorSet.h
cocos/renderer/gfx-metal/MTLDescriptorSet.mm
cocos/renderer/gfx-metal/MTLQueue.h
cocos/renderer/gfx-metal/MTLQueue.mm
cocos/renderer/gfx-metal/MTLRenderPass.h
Expand Down
13 changes: 10 additions & 3 deletions cocos/renderer/core/gfx/GFXCommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CC_DLL CommandBuffer : public GFXObject {
virtual void destroy() = 0;
virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) = 0;
virtual void end() = 0;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector<Color> &colors, float depth, int stencil) = 0;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) = 0;
virtual void endRenderPass() = 0;
virtual void bindPipelineState(PipelineState *pso) = 0;
virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) = 0;
Expand All @@ -31,16 +31,23 @@ class CC_DLL CommandBuffer : public GFXObject {
virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) = 0;
virtual void draw(InputAssembler *ia) = 0;
virtual void updateBuffer(Buffer *buff, void *data, uint size, uint offset = 0) = 0;
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList &regions) = 0;
virtual void execute(const CommandBufferList &cmdBuffs, uint32_t count) = 0;
virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) = 0;
virtual void execute(const CommandBuffer *const *cmdBuffs, uint32_t count) = 0;

CC_INLINE void begin() { begin(nullptr, 0, nullptr); }
CC_INLINE void begin(RenderPass *renderPass) { begin(renderPass, 0, nullptr); }
CC_INLINE void begin(RenderPass *renderPass, uint subpass) { begin(renderPass, subpass, nullptr); }
CC_INLINE void execute(const CommandBufferList &cmdBuffs, uint32_t count) { execute(cmdBuffs.data(), count); }
CC_INLINE void bindDescriptorSet(uint set, DescriptorSet *descriptorSet) { bindDescriptorSet(set, descriptorSet, 0, nullptr); }
CC_INLINE void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, const vector<uint> &dynamicOffsets) {
bindDescriptorSet(set, descriptorSet, dynamicOffsets.size(), dynamicOffsets.data());
}
CC_INLINE void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector<Color> &colors, float depth, int stencil) {
beginRenderPass(renderPass, fbo, renderArea, colors.data(), depth, stencil);
}
CC_INLINE void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList &regions) {
copyBuffersToTexture(buffers.data(), texture, regions.data(), regions.size());
}

CC_INLINE Device *getDevice() const { return _device; }
CC_INLINE Queue *getQueue() const { return _queue; }
Expand Down
6 changes: 5 additions & 1 deletion cocos/renderer/core/gfx/GFXDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class CC_DLL Device : public Object {
virtual DescriptorSetLayout *createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) = 0;
virtual PipelineLayout *createPipelineLayout(const PipelineLayoutInfo &info) = 0;
virtual PipelineState *createPipelineState(const PipelineStateInfo &info) = 0;
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList &regions) = 0;
virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) = 0;

CC_INLINE void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList &regions) {
copyBuffersToTexture(buffers.data(), dst, regions.data(), regions.size());
}

CC_INLINE API getGfxAPI() const { return _API; }
CC_INLINE const String &getDeviceName() const { return _deviceName; }
Expand Down
19 changes: 8 additions & 11 deletions cocos/renderer/gfx-gles2/GLES2CommandBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ void GLES2CommandBuffer::end() {
_isInRenderPass = false;
}

void GLES2CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector<Color> &colors, float depth, int stencil) {
void GLES2CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) {
_isInRenderPass = true;

GLES2CmdBeginRenderPass *cmd = _gles2Allocator->beginRenderPassCmdPool.alloc();
cmd->gpuRenderPass = ((GLES2RenderPass *)renderPass)->gpuRenderPass();
cmd->gpuFBO = ((GLES2Framebuffer *)fbo)->gpuFBO();
cmd->renderArea = renderArea;
cmd->numClearColors = (uint32_t)colors.size();
for (uint i = 0; i < colors.size(); ++i) {
cmd->numClearColors = cmd->gpuRenderPass->colorAttachments.size();
for (uint i = 0; i < cmd->numClearColors; ++i) {
cmd->clearColors[i] = colors[i];
}
cmd->clearDepth = depth;
Expand Down Expand Up @@ -255,19 +255,16 @@ void GLES2CommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint
}
}

void GLES2CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList &regions) {
void GLES2CommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) {
if ((_type == CommandBufferType::PRIMARY && !_isInRenderPass) ||
(_type == CommandBufferType::SECONDARY)) {
GLES2GPUTexture *gpuTexture = ((GLES2Texture *)texture)->gpuTexture();
if (gpuTexture) {
GLES2CmdCopyBufferToTexture *cmd = _gles2Allocator->copyBufferToTextureCmdPool.alloc();
cmd->gpuTexture = gpuTexture;
cmd->buffers.resize(buffers.size());
cmd->regions.resize(regions.size());
for (uint i = 0; i < static_cast<uint>(regions.size()); ++i) {
cmd->buffers[i] = buffers[i];
cmd->regions[i] = regions[i];
}
cmd->buffers = buffers;
cmd->regions = regions;
cmd->count = count;

_cmdPackage->copyBufferToTextureCmds.push(cmd);
_cmdPackage->cmds.push(GFXCmdType::COPY_BUFFER_TO_TEXTURE);
Expand All @@ -277,7 +274,7 @@ void GLES2CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Tex
}
}

void GLES2CommandBuffer::execute(const CommandBufferList &cmdBuffs, uint32_t count) {
void GLES2CommandBuffer::execute(const CommandBuffer *const *cmdBuffs, uint32_t count) {
for (uint i = 0; i < count; ++i) {
GLES2CommandBuffer *cmdBuff = (GLES2CommandBuffer *)cmdBuffs[i];

Expand Down
6 changes: 3 additions & 3 deletions cocos/renderer/gfx-gles2/GLES2CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CC_GLES2_API GLES2CommandBuffer : public CommandBuffer {

virtual void begin(RenderPass *renderPass = nullptr, uint subpass = 0, Framebuffer *frameBuffer = nullptr) override;
virtual void end() override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector<Color> &colors, float depth, int stencil) override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) override;
virtual void endRenderPass() override;
virtual void bindPipelineState(PipelineState *pso) override;
virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override;
Expand All @@ -36,8 +36,8 @@ class CC_GLES2_API GLES2CommandBuffer : public CommandBuffer {
virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) override;
virtual void draw(InputAssembler *ia) override;
virtual void updateBuffer(Buffer *buff, void *data, uint size, uint offset) override;
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList &regions) override;
virtual void execute(const CommandBufferList &cmdBuffs, uint32_t count) override;
virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override;
virtual void execute(const CommandBuffer *const *cmdBuffs, uint32_t count) override;

private:
void BindStates();
Expand Down
12 changes: 6 additions & 6 deletions cocos/renderer/gfx-gles2/GLES2Commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2142,7 +2142,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) {
}
case GFXCmdType::COPY_BUFFER_TO_TEXTURE: {
GLES2CmdCopyBufferToTexture *cmd = cmdPackage->copyBufferToTextureCmds[cmdIdx];
GLES2CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions);
GLES2CmdFuncCopyBuffersToTexture(device, cmd->buffers, cmd->gpuTexture, cmd->regions, cmd->count);
break;
}
default:
Expand All @@ -2152,7 +2152,7 @@ void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmdPackage) {
}
}

void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList &buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopyList &regions) {
void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const uint8_t *const *buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count) {
GLuint &glTexture = device->stateCache->glTextures[device->stateCache->texUint];
if (glTexture != gpuTexture->glTexture) {
glBindTexture(gpuTexture->glTarget, gpuTexture->glTexture);
Expand All @@ -2166,7 +2166,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList
case GL_TEXTURE_2D: {
uint w;
uint h;
for (size_t i = 0; i < regions.size(); ++i) {
for (size_t i = 0; i < count; ++i) {
const BufferTextureCopy &region = regions[i];
w = region.texExtent.width;
h = region.texExtent.height;
Expand Down Expand Up @@ -2197,7 +2197,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList
case GL_TEXTURE_2D_ARRAY: {
uint w;
uint h;
for (size_t i = 0; i < regions.size(); ++i) {
for (size_t i = 0; i < count; ++i) {
const BufferTextureCopy &region = regions[i];
uint d = region.texSubres.layerCount;
uint layerCount = d + region.texSubres.baseArrayLayer;
Expand Down Expand Up @@ -2235,7 +2235,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList
uint w;
uint h;
uint d;
for (size_t i = 0; i < regions.size(); ++i) {
for (size_t i = 0; i < count; ++i) {
const BufferTextureCopy &region = regions[i];
w = region.texExtent.width;
h = region.texExtent.height;
Expand Down Expand Up @@ -2270,7 +2270,7 @@ void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList
uint w;
uint h;
uint f;
for (size_t i = 0; i < regions.size(); ++i) {
for (size_t i = 0; i < count; ++i) {
const BufferTextureCopy &region = regions[i];
uint faceCount = region.texSubres.baseArrayLayer + region.texSubres.layerCount;
for (f = region.texSubres.baseArrayLayer; f < faceCount; ++f) {
Expand Down
12 changes: 7 additions & 5 deletions cocos/renderer/gfx-gles2/GLES2Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,17 @@ class GLES2CmdUpdateBuffer : public GFXCmd {
class GLES2CmdCopyBufferToTexture : public GFXCmd {
public:
GLES2GPUTexture *gpuTexture = nullptr;
BufferDataList buffers;
BufferTextureCopyList regions;
const uint8_t *const *buffers = nullptr;
const BufferTextureCopy *regions = nullptr;
uint count = 0u;

GLES2CmdCopyBufferToTexture() : GFXCmd(GFXCmdType::COPY_BUFFER_TO_TEXTURE) {}

virtual void clear() override {
gpuTexture = nullptr;
buffers.clear();
regions.clear();
buffers = nullptr;
regions = nullptr;
count = 0u;
}
};

Expand Down Expand Up @@ -168,7 +170,7 @@ CC_GLES2_API void GLES2CmdFuncDestroyInputAssembler(GLES2Device *device, GLES2GP
CC_GLES2_API void GLES2CmdFuncCreateFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO);
CC_GLES2_API void GLES2CmdFuncDestroyFramebuffer(GLES2Device *device, GLES2GPUFramebuffer *gpuFBO);
CC_GLES2_API void GLES2CmdFuncExecuteCmds(GLES2Device *device, GLES2CmdPackage *cmd_package);
CC_GLES2_API void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const BufferDataList &buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopyList &regions);
CC_GLES2_API void GLES2CmdFuncCopyBuffersToTexture(GLES2Device *device, const uint8_t *const *buffers, GLES2GPUTexture *gpuTexture, const BufferTextureCopy *regions, uint count);

} // namespace gfx
} // namespace cc
Expand Down
4 changes: 2 additions & 2 deletions cocos/renderer/gfx-gles2/GLES2Device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ PipelineState *GLES2Device::createPipelineState(const PipelineStateInfo &info) {
return nullptr;
}

void GLES2Device::copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList &regions) {
GLES2CmdFuncCopyBuffersToTexture(this, buffers, ((GLES2Texture *)dst)->gpuTexture(), regions);
void GLES2Device::copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) {
GLES2CmdFuncCopyBuffersToTexture(this, buffers, ((GLES2Texture *)dst)->gpuTexture(), regions, count);
}

} // namespace gfx
Expand Down
2 changes: 1 addition & 1 deletion cocos/renderer/gfx-gles2/GLES2Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CC_GLES2_API GLES2Device : public Device {
virtual DescriptorSetLayout *createDescriptorSetLayout(const DescriptorSetLayoutInfo &info) override;
virtual PipelineLayout *createPipelineLayout(const PipelineLayoutInfo &info) override;
virtual PipelineState *createPipelineState(const PipelineStateInfo &info) override;
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *dst, const BufferTextureCopyList &regions) override;
virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *dst, const BufferTextureCopy *regions, uint count) override;

CC_INLINE bool useVAO() const { return _useVAO; }
CC_INLINE bool useDrawInstanced() const { return _useDrawInstanced; }
Expand Down
20 changes: 9 additions & 11 deletions cocos/renderer/gfx-gles3/GLES3CommandBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ void GLES3CommandBuffer::end() {
_isInRenderPass = false;
}

void GLES3CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector<Color> &colors, float depth, int stencil) {
void GLES3CommandBuffer::beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) {
_isInRenderPass = true;

GLES3CmdBeginRenderPass *cmd = _gles3Allocator->beginRenderPassCmdPool.alloc();
cmd->gpuRenderPass = ((GLES3RenderPass *)renderPass)->gpuRenderPass();
cmd->gpuFBO = ((GLES3Framebuffer *)fbo)->gpuFBO();
cmd->renderArea = renderArea;
cmd->numClearColors = (uint32_t)colors.size();
for (uint i = 0; i < colors.size(); ++i) {
cmd->numClearColors = cmd->gpuRenderPass->colorAttachments.size();
for (uint i = 0; i < cmd->numClearColors; ++i) {
cmd->clearColors[i] = colors[i];
}
cmd->clearDepth = depth;
Expand Down Expand Up @@ -260,20 +260,18 @@ void GLES3CommandBuffer::updateBuffer(Buffer *buff, void *data, uint size, uint
}
}

void GLES3CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList &regions) {
void GLES3CommandBuffer::copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) {
if ((_type == CommandBufferType::PRIMARY && !_isInRenderPass) ||
(_type == CommandBufferType::SECONDARY)) {

GLES3GPUTexture *gpuTexture = ((GLES3Texture *)texture)->gpuTexture();
if (gpuTexture) {
GLES3CmdCopyBufferToTexture *cmd = _gles3Allocator->copyBufferToTextureCmdPool.alloc();
cmd->gpuTexture = gpuTexture;
cmd->buffers.resize(buffers.size());
cmd->regions.resize(regions.size());
for (uint i = 0; i < static_cast<uint>(regions.size()); ++i) {
cmd->buffers[i] = buffers[i];
cmd->regions[i] = regions[i];
}
cmd->gpuTexture = gpuTexture;
cmd->buffers = buffers;
cmd->regions = regions;
cmd->count = count;

_cmdPackage->copyBufferToTextureCmds.push(cmd);
_cmdPackage->cmds.push(GFXCmdType::COPY_BUFFER_TO_TEXTURE);
Expand All @@ -283,7 +281,7 @@ void GLES3CommandBuffer::copyBuffersToTexture(const BufferDataList &buffers, Tex
}
}

void GLES3CommandBuffer::execute(const CommandBufferList &cmdBuffs, uint32_t count) {
void GLES3CommandBuffer::execute(const CommandBuffer *const *cmdBuffs, uint32_t count) {
for (uint i = 0; i < count; ++i) {
GLES3CommandBuffer *cmdBuff = (GLES3CommandBuffer *)cmdBuffs[i];

Expand Down
6 changes: 3 additions & 3 deletions cocos/renderer/gfx-gles3/GLES3CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CC_GLES3_API GLES3CommandBuffer : public CommandBuffer {

virtual void begin(RenderPass *renderPass, uint subpass, Framebuffer *frameBuffer) override;
virtual void end() override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const vector<Color> &colors, float depth, int stencil) override;
virtual void beginRenderPass(RenderPass *renderPass, Framebuffer *fbo, const Rect &renderArea, const Color *colors, float depth, int stencil) override;
virtual void endRenderPass() override;
virtual void bindPipelineState(PipelineState *pso) override;
virtual void bindDescriptorSet(uint set, DescriptorSet *descriptorSet, uint dynamicOffsetCount, const uint *dynamicOffsets) override;
Expand All @@ -36,8 +36,8 @@ class CC_GLES3_API GLES3CommandBuffer : public CommandBuffer {
virtual void setStencilCompareMask(StencilFace face, int ref, uint mask) override;
virtual void draw(InputAssembler *ia) override;
virtual void updateBuffer(Buffer *buff, void *data, uint size, uint offset) override;
virtual void copyBuffersToTexture(const BufferDataList &buffers, Texture *texture, const BufferTextureCopyList &regions) override;
virtual void execute(const CommandBufferList &cmdBuffs, uint32_t count) override;
virtual void copyBuffersToTexture(const uint8_t *const *buffers, Texture *texture, const BufferTextureCopy *regions, uint count) override;
virtual void execute(const CommandBuffer *const *cmdBuffs, uint32_t count) override;

private:
void BindStates();
Expand Down

0 comments on commit 03d9f9e

Please sign in to comment.